为了账号安全,请及时绑定邮箱和手机立即绑定

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

三栏布局,假定中间宽度固定为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>
点击查看更多内容
4人点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
Web前端工程师
手记
粉丝
0
获赞与收藏
20

关注作者,订阅最新文章

阅读免费教程

感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消