我在页面中心制作了一个小 div,它有一个固定的页脚,但 div 是可滚动的。
在我看来,有两种方法可以做到:
- 使用
position:fixed
:固定位置实际上相对于浏览器窗口有效,但我想要相对于我的小 div 的位置 - 使用
position:absolute
:使用bottom:0;
我最初解决了这个问题,但页脚滚动了 div 文本。
HTML:
<div id="wrapper">
<div id="box">
<div id="header">
<h1>Heading</h1>
</div>
<div id="content">
Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text Some text
</div>
<div id="footer">
<p>Fooooooooooooooooooooooooooter</p>
</div>
</div>
</div>
CSS:
#wrapper{
width:600px;
height:500px;
border:thin solid #c00;
}
#box {
width:400px;
height:300px;
margin:100px auto;
border:medium dashed #c00;
position:relative;
overflow:auto;
}
#content {
background-color:rgba(0,0,208,0.1);
}
#footer {
position:absolute;
bottom:0px;
width:100%;
height:50px;
background-color:rgba(0,0,0,0.8);
color:#fff;
}
看:JSfiddle
如何使此 div 的页脚固定?