圣杯布局(左右固定,中间自适应)

flex布局

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0">
    <title>xxx</title>
    <!-- IMPORT CSS -->
    <link rel="stylesheet" href="css/reset.min.css">
    <style>
        html,
        body {
            overflow: hidden;
        }

        .container {
            display: flex;
            justify-content: space-between;
            height: 100%;
        }

        .left,
        .right {
            flex: 0 0 200px;
            height: 200px;
            background: lightblue;
        }

        .center {
            flex: 1;
            min-height: 400px;
            background: lightsalmon;
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="left"></div>
        <div class="center"></div>
        <div class="right"></div>
    </div>
</body>

</html>

 

定位,定位元素(脱离文档流了)

<style>
    html,
    body {
        height: 100%;
        overflow: hidden;
    }

    .container {
        position: relative;
        height: 100%;
    }

    .left,
    .right {
        position: absolute;
        top: 0;
        width: 200px;
        min-height: 200px;
        background: lightblue;
    }

    .left {
        left: 0;
    }

    .right {
        right: 0;
    }

    .center {
     positon: absolute   left:200px
     right:200px 
background: lightsalmon; } </style>

 浮动布局

  <!--浮动布局  -->
    <section class="layout float">
      <style media="screen">
      .layout.float .left{
        float:left;
        width:300px;
        background: red;
      }
      .layout.float .center{
        background: yellow;
      }
      .layout.float .right{
        float:right;
        width:300px;
        background: blue;
      }
      </style>
      <h1>三栏布局</h1>
      <article class="left-right-center">
        <div class="left"></div>
        <div class="right"></div>
        <div class="center">
          <h2>浮动解决方案</h2>
          1.这是三栏布局的浮动解决方案;
          2.这是三栏布局的浮动解决方案;
          3.这是三栏布局的浮动解决方案;
          4.这是三栏布局的浮动解决方案;
          5.这是三栏布局的浮动解决方案;
          6.这是三栏布局的浮动解决方案;
        </div>
      </article>
    </section>

 

网格布局,详解;http://www.ruanyifeng.com/blog/2019/03/grid-layout-tutorial.html

<!-- 网格布局 -->
    <section class="layout grid">
      <style>
        .layout.grid .left-center-right{
          width:100%;
          display: grid;
          grid-template-rows: 100px;
          grid-template-columns: 300px auto 300px;
        }
        .layout.grid .left-center-right>div{

        }
        .layout.grid .left{
          width: 300px;
          background: red;
        }
        .layout.grid .center{
          background: yellow;
        }
        .layout.grid .right{

          background: blue;
        }
      </style>
      <h1>三栏布局</h1>
      <article class="left-center-right">
        <div class="left"></div>
        <div class="center">
          <h2>网格布局解决方案</h2>
          1.这是三栏布局的浮动解决方案;
          2.这是三栏布局的浮动解决方案;
          3.这是三栏布局的浮动解决方案;
          4.这是三栏布局的浮动解决方案;
          5.这是三栏布局的浮动解决方案;
          6.这是三栏布局的浮动解决方案;
        </div>
        <div class="right"></div>
      </article>
    </section>

 

posted @ 2021-03-13 22:30  全情海洋  阅读(148)  评论(0编辑  收藏  举报