头部固定 剩余高度自适应布局

头部固定、剩余高度自适应布局可以用很多方式, 比如flex 、calc() 等等,但是兼容性没那么好, 现在列举些兼容比较好的方案

方案1
代码如下

  <div>
    <div class="top">我是头部</div>
    <div class="middle">
    	我是主体信息
    </div>
  </div>
<style>
	* {
    margin: 0;
    padding: 0;
}
html, body {
    width: 100%;
    height: 100%;
}
.top {
    width: 100%;
    height: 70px;
    background-color: red;
    font-size: 30px;
    line-height: 70px;
}
.middle {
    position: absolute;
    top: 70px;
    bottom: 40px;
    width: 100%;
    background-color: sandybrown;
    font-size: 70px;
    text-align: center;
}
</style>

效果
在这里插入图片描述
方案 2

<div class="outer">
    <div class="top">我是头部</div>
    <div class="middle">
    	我是主体信息
    </div>
  </div>
<style>
	* {
    margin: 0;
    padding: 0;
}
html, body {
    width: 100%;
    height: 100%;
}
.outer{
	height: 100%;
	padding-top: 70px;
	box-sizing: border-box;
}
.top {
    width: 100%;
    height: 70px;
    background-color: yellowgreen;
    font-size: 30px;
    line-height: 70px;
    position: absolute;
    top: 0px;
    left: 0;
}
.middle {
    width: 100%;
    height: 100%;
    background-color: beige;
    font-size: 70px;
    text-align: center;
}
</style>

效果
在这里插入图片描述

方案 3
将方案二 .top代码修改如下 效果一样

.top {
    width: 100%;
    height: 70px;
    background-color: yellowgreen;
    font-size: 30px;
    line-height: 70px;
    margin-top: -70px;
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值