css实现div填充剩余高度 高度自适应

 利用父元素的padding-top 和 头部div的margin-top(为负) 搭配巧妙的实现,代码如下:

HTML代码: 

header
content

css代码:

html,body{height:100%;margin:0;padding:0;}
.father { height: 100%; padding: 50px 0 0; box-sizing: border-box ; }
.header { height: 50px; margin: -50px 0 0; background: blue; }
.content {height: 100%; background: red; }

 

你可能感兴趣的:(css)