继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

三栏布局之中间固定,左右两栏自适应几种方案

agugua
关注TA
已关注
手记 1
粉丝 0
获赞 20

三栏布局,假定中间宽度固定为200px,左右两栏自适应
grid布局,请到最新chrome浏览器上运行体验

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>三栏布局之中间固定,左右两栏自适应</title>
    <style type="text/css">
      body {
        margin: 0;
        padding: 0;
      }
      section.layout {
        margin-bottom: 50px;
        text-align: center;
        color: white;
      }
      .left {
        background-color: #65d;
      }
      .center {
        background-color: #f05;
      }
      .right {
        background-color: blue;
      }
    </style>
  </head>
  <body>
    <section class="layout flex">
      <!-- flex布局方案 -->
      <style>
        .layout.flex .page {
          display: flex;

        }
        .layout.flex .left, .layout.flex .right {
          flex: 1;
        }

        .layout.flex .center {
          width: 200px;
        }
      </style>
      <article class="page">
        <div class="left">左边自适应</div>
        <div class="center">flex布局-中间固定宽度部分</div>
        <div class="right">右边自适应</div>
      </article>
    </section>

    <section class="layout table">
      <!-- table 布局方案 -->
      <style>
        .layout.table .page {
          display: table;
          width: 100%;
        }
        .layout.table .page>div {
          display: table-cell;
        }
        .layout.table .center {
          width: 200px;
        }
      </style>
      <article class="page">
        <div class="left">左边自适应</div>
        <div class="center">table布局-中间固定宽度部分</div>
        <div class="right">右边自适应</div>
      </article>
    </section>

    <section class="layout grid">
      <!-- 网格布局方案 -->
      <style>
        .layout.grid .page {
          display: grid;
          grid-template-rows: 100%;
          grid-template-columns: auto 200px auto;
        }
      </style>
      <article class="page">
        <div class="left">左边自适应</div>
        <div class="center">
          grid布局-中间固定宽度部分
        </div>
        <div class="right">右边自适应</div>
      </article>
    </section>
  </body>
</html>
打开App,阅读手记
4人推荐
发表评论
随时随地看视频慕课网APP