方案1:
Html:
1 2 3 4 | <div class="outer"> <div class="A"> 头部DIV </div> <div class="B">下部DIV </div></div> |
CSS:
1 2 3 4 5 | html,body { height: 100%; padding: 0; margin: 0; }.outer { height: 100%; padding: 100px 0 0; box-sizing: border-box ; position: relative; }.A { height: 100px; background: #BBE8F2; position: absolute; top: 0 ; left: 0 ; width: 100%; }.B { height: 100%; background: #D9C666; } |
方案2:
HTML:
1 2 3 4 | <div class="outer"> <div class="A">头部DIV</div> <div class="B">下部DIV</div></div> |
CSS:
1 2 3 4 5 | html,body { height: 100%; padding: 0; margin: 0; }.outer { height: 100%; padding: 100px 0 0; box-sizing: border-box ; }.A { height: 100px; margin: -100px 0 0; background: #BBE8F2; }.B { height: 100%; background: #D9C666; } |
本文介绍了两种实现固定头部和自适应内容区域的网页布局方案。方案一使用绝对定位将头部固定,剩余部分通过相对定位填充剩余空间;方案二则通过负边距调整头部位置,使主体内容自然填充页面。
2410

被折叠的 条评论
为什么被折叠?



