二欄布局之左側(cè)固定右側(cè)自適應(yīng)布局方案

1.png
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style media="screen">
    body {
      margin: 0;
      padding: 0;
    }
    .left {
      height: 100px;
      background-color: pink;
    }
    .main {
      height: 100px;
      background-color: #5fcfcd;
    }
    .layout {
      margin: 10px 0;
       border: 5px solid grey;
    }
  </style>
</head>
<body>
  <section class="layout float">
    <!-- 浮動布局方案 -->
    <style type="text/css">
      .layout.float .page {
        zoom: 1;
      }
      .layout.float .page::after {
        content: '';
        display: block;
        clear: both;
      }
      .layout.float .left {
        float: left;
        width: 150px;
        margin-right: 10px;
      }
      .layout.float .main {
        overflow: auto;
      }
    </style>
    <article class="page">
      <div class="left">浮云布局--左側(cè)固定內(nèi)容框</div>
      <div class="main">浮云布局--右側(cè)自適應(yīng)內(nèi)容框</div>
    </article>
  </section>


  <section class="layout absolute">
    <!-- 絕對定位布局
      最大缺陷: 父級高度無法撐開;
   -->
    <style type="text/css">
      .layout.absolute .page {
        position: relative;
      }
      .layout.absolute .left {
        position: absolute;
        width: 150px;
      }
      .layout.absolute .main {
        position: absolute;
        left: 160px;
        right: 0;
      }
    </style>
    <article class="page">
      <div class="left">絕對定位布局--左側(cè)固定內(nèi)容框</div>
      <div class="main">絕對定位布局--右側(cè)自適應(yīng)內(nèi)容框</div>
    </article>
  </section>


  <section class="layout flex" style="margin-top:110px;">
    <!-- flex 布局方案 -->
    <style type="text/css">
      .layout.flex .page {
        display: flex;
      }
      .layout.flex .left {
        flex-basis: 150px;
      }
      .layout.flex .main {
        flex: 1;
      }
    </style>
    <article class="page">
      <div class="left">flex布局--左側(cè)固定內(nèi)容框</div>
      <div class="main">flex布局--右側(cè)自適應(yīng)內(nèi)容框</div>
    </article>

  </section>

  <section class="layout table">
    <!-- table布局布局方案 -->
    <style type="text/css">
      .layout.table .page {
        display: table;
        width: 100%;
      }
      .layout.table .left {
        display: table-cell;
        width: 150px;
      }
      .layout.table .main {
        display: table-cell;
      }
    </style>

    <article class="page">
      <div class="left">table布局--左側(cè)固定內(nèi)容框</div>
      <div class="main">table布局--右側(cè)自適應(yīng)內(nèi)容框</div>
    </article>
  </section>

  <section class="layout grid">
    <!-- grid布局方案 -->
    <style type="text/css">
      .layout.grid .page {
        display: grid;
        grid-template-columns: 150px auto;
      }
    </style>
    <article class="page">
      <div class="left">grid布局--左側(cè)固定內(nèi)容框</div>
      <div class="main">grid布局--右側(cè)自適應(yīng)內(nèi)容框</div>
    </article>
  </section>
</body>
</html>

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容