利用父元素的padding-top 和 头部div的margin-top(为负) 搭配巧妙的实现,代码如下:
HTML代码:
<div class="father">
<div class="header">header</div>
<div class="content">content</div>
</div>
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; }