上下定高 中间自适应_上下高度固定(100px),中间自适应

1、绝对定位

absolute

html,body{

height:100%;

}

.container>div {

position: absolute;

width : 100%;

}

.header {

top: 0;

height: 100px;

background-color: red;

}

.body {

top: 100px;

bottom: 100px;

background-color: blue;

}

.footer {

bottom: 0;

height: 100px;

background-color: red;

}

2、弹性布局

flex

html,body{

height:100%;

}

.container {

height: 100%;

display: flex;

flex-direction: column;

}

.body {

flex: 1 1 auto;

background-color: blue;

}

.header, .footer {

height: 100px;

flex: 0 0 auto;

background-color: red;

}

3、网格布局

grid

html,body{

height:100%;

}

.container {

display: grid;

height : 100%;

grid-template-rows : 100px auto 100px;

}

.header, .footer{

background-color:red;

}

.body {

background-color:blue;

}

4、表格布局

table

html,body{

height:100%;

}

.container {

display: table;

height : 100%;

width :100%;

}

.container>div{

display: table-row;

}

.header, .footer {

height:100px;

background-color:red;

}

.body {

background-color:blue;

}

PS:不知道为什么表格布局里面设置背景颜色无效,自己在那时还是没有解决。当然这也算是在这种情况下使用表格布局的一个缺点吧,背景色容易被屏蔽。有哪位童鞋能够很好处理这个问题的还请指教一波,谢谢> <

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值