三栏布局,上下固定高度,中间自适应,四种实现方式

第一种:定位布局

<!-- 定位布局 -->
    <style>
        body html{
            height: 100%;
        }
        .position>div{
            position: absolute;
            width: 100%;
        }
        .top{
            top: 0;
            background: red;
            height: 100px;
        }
        .center{
            top: 100px;
            bottom: 100px;
            background: blue;
        }
        .bottom{
            bottom: 0;
            background: green;
            height: 100px;
        }
    </style>
</head>
<body>
<section class="position">
    <div class="top"></div>
    <div class="center"></div>
    <div class="bottom"></div>
</section>
</body>

第二种:flex布局

    <style>
        body html{
            height: 100%;
        }
        .flex{
            display: flex;
            height: 100%;
            flex-direction: column; /*定义排列方向为竖排*/
        }
        .top{
            height: 100px;
            background: red;
        }
        .center{
            flex: 1;
            overflow: auto;
            background: blue;
        }
        .bottom{
            height: 100px;
            background: green;
        }
    </style>
</head>
<body>
<section class="flex">
    <div class="top"></div>
    <div class="center">
        <p>中间自适应</p>
        <p>中间自适应</p>
        <p>中间自适应</p>
        <p>中间自适应</p>
        <p>中间自适应</p>
        <p>中间自适应</p>
    </div>
    <div class="bottom"></div>
</section>
</body>

第三种:table布局

 <style>
        body html{
            height: 100%;
        }
        .table{
            display: table;
            height: 100%;
            width: 100%;
        }
        .table>div{
            display: table-row;
            vertical-align: middle;
        }
        .top{
            height: 100px;
            width: 100%;
            background: red;
        }
        .center{
            overflow: auto;
            background: blue;
        }
        .bottom{
            height: 100px;
            width: 100%;
            background: green;
        }
    </style>
</head>
<body>
<section class="table">
    <div class="top"></div>
    <div class="center"></div>
    <div class="bottom"></div>
</section>
</body>

第四种:网格(grid)布局

<style>
        .grid{
            display: grid;
            height: 100%;
            grid-template-rows: 100px auto 100px;
        }
        .top{
            background: red;
        }
        .center{
            background: blue;
        }
        .bottom{
            background: green;
        }
    </style>
</head>
<body>
<section class="grid">
    <div class="top"></div>
    <div class="center"></div>
    <div class="bottom"></div>
</section>
</body>
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值