【发布时间】:2016-07-31 22:50:19
【问题描述】:
我想要一个覆盖整个页面正文的 div,即使内容必须滚动。
典型的做法是使用绝对定位的 div,同时在 html 和 body 上设置 100% 的高度。
但是,如果页面上的其他内容比屏幕上的内容长,我的 100% 高度 div 只会覆盖窗口的可见区域,并且不会一直延伸到页面末尾。
示例:http://jsbin.com/wuqezaceteme/1/
CSS:
body, html {
margin:0;
padding:0;
height:100%;
width:100%;
}
body {
position:relative;
}
.wrapper {
position:absolute; /* can't use fixed */
background:yellow;
height:100%;
width:100%;
top:0;
left:0;
}
.box {
height:2200px;
}
HTML:
<div class="wrapper">
Scroll down (yellow box does not go to bottom when scrolling)
</div>
<div class="box">box</div>
</body>
【问题讨论】:
-
从
body, html中删除height:100%。 -
请问为什么不能用fixed?
-
@lolka_bolka 我不能使用 fixed,因为我的包装器实际上将包含另一个 div,我需要相对于滚动内容保持静态。
标签: html css css-position