CSS+div布局,上中下三行div,上下固定高度,中间铺满

在这里插入图片描述
方法一:使用定位,
父元素相对定位 position:relative;
子元素绝对定位 position:absolute;
上下div固定高度,中间div的 top bottom 偏移量为上下div的高度

<div id="wrap">
    <div id="head"></div>
    <div id="main"></div>
    <div id="foot"></div>
</div>
* {
    margin: 0px;
    padding: 0px;
}

html,
body {
    height: 100%;
}

#wrap {
    width: 100%;
    height: 100%;
    position: relative;
}

#head {
    width: 100%;
    height: 80px;
    background-color: aquamarine;
    position: absolute;
}

#main {
    width: 100%;
    background-color: blueviolet;
    position: absolute;
    top: 80px;
    bottom: 120px;
}

#foot {
    width: 100%;
    height: 120px;
    background-color: brown;
    position: absolute;
    bottom: 0px;
}

方法二:使用弹性盒子
父元素设置 display:flex;      flex-direction: column;

( flex-direction 属性决定主轴的方向 column主轴为垂直方向,起点在上沿。)

上下div设置固定高度,中间div设置 flex: 1;

* {
    margin: 0px;
    padding: 0px;
}

html,
body {
    height: 100%;
}

#wrap {
    display: flex;
    flex-direction: column;
}

#head {
    width: 100%;
    height: 80px;
    background-color: aquamarine;
}

#main {
    width: 100%;
    height: 100%;
    flex: 1;
    background-color: blueviolet;
}

#foot {
    width: 100%;
    height: 120px;
    background-color: brown;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值