上下定高中间自适应的三栏布局

共有四种实现方法,其原理与左右定宽中间自适应差不多,更多适用于移动端。

    *{
      padding: 0;
      margin: 0;
    }
    html, body{
      height: 100%;
    }
    .layout{
      height: 100%;
    }
    .layout article > div{
      width: 100px;
    }

1.flex布局

  <!-- flex布局 -->
  <section class="layout flex">
    <style>
      .layout.flex{
        height: 100%;
      }
      .layout.flex article{
        width: 100px;
        height: 100%;
        display: flex;
        flex-direction: column;
      }
      .layout.flex .top{
        height: 100px;
        background-color: red;
      }
      .layout.flex .middle{
        flex: 1;
        background-color: pink;
        overflow: auto;
      }
      .layout.flex .bottom{
        height: 100px;
        background-color: green;
      }
    </style>
    <article>
      <div class="top"></div>
      <div class="middle">
        <p>center</p>
      </div>
      <div class="bottom"></div>
    </article>
  </section>

 

2.绝对定位布局

  <!-- position布局 -->
  <section class="layout position">
    <style>
      .layout.position{
        margin-left: 120px;
      }
      .layout.position article{
        width: 100px;
        height: 100%;
      }
      .layout.position .top{
        position: absolute;
        top: 0;
        height: 200px;
        background-color: #999;
      }
      .layout.position .middle{
        position: absolute;
        top: 200px;
        bottom: 100px;
        background-color: green;
      }
      .layout.position .bottom{
        position: absolute;
        bottom: 0;
        background-color: red;
        height: 100px;
      }
      .clear{
        clear: both;
      }
    </style>
    <article>
      <div class="top"></div>
      <div class="middle"></div>
      <div class="bottom"></div>
      <div class="clear"></div>
    </article>
  </section>

 

3.表格布局

  <!-- table布局 -->
  <section class="layout table">
    <style>
      .layout.table article{
        width: 100px;
        height: 100%;
        display: table;
      }
      .layout.table .top{
        height: 150px;
        background: red;
        display: table-row;
      }
      .layout.table .middle{
        display: table-row;
        overflow: auto;
        background: yellow;
      }
      .layout.table .bottom{
        display: table-row;
        background: green;
        height: 100px;
      }
    </style>
    <article>
      <!-- div中如果不包含内容,页面会显示空白 -->
      <div class="top">
        <p>top</p>
      </div>
      <div class="middle">
        <p>middle</p>
      </div>
      <div class="bottom">
        <p>bottom</p>
      </div>
    </article>
  </section>

 

4.grid布局

  <!-- grid布局 -->
  <section class="layout grid">
    <style>
      .layout.grid{
        margin-left: 220px;
      }
      .layout.grid article{
        height: 100%;
        width: 100px;
        display: grid;
        grid-template-rows: 150px auto 120px;
        grid-template-columns: 100px;
      }
      .layout.grid .top{
        background-color: yellow;
      }
      .layout.grid .middle{
        background-color: peru;
      }
      .layout.grid .bottom{
        background-color: pink;
      }
    </style>
    <article>
      <div class="top"></div>
      <div class="middle"></div>
      <div class="bottom"></div>
    </article>
  </section>

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值