所以我有一个页脚:
<div id="footer" >
<div style="padding:20px;">
Footer
</div>
</div>
这是一个带有样式的容器:
#page { width:964px; margin:0 auto; }
我需要将页脚div固定在浏览器底部。问题是,如果我添加:
position:absolute;
bottom:0;
以前的某些 div 与页脚相交,我需要自己设置高度和宽度。
html, body {
height: 100%;
}
.wrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -142px; /* the bottom margin is the negative value of the footer's height */
}
.footer, .push {
height: 142px; /* .push must be the same height as .footer */
}
The HTML
<div class="wrapper">
<p>wrapper text here</p>
<div class="push"></div>
</div>
<div class="footer">
<p>footer text here.</p>
</div>
这不完全是你要求的,但这是我使用position: fixed
实现的类似方案。
为了实现你想要的效果,你需要使用position: absolute
。然后你需要手动设置元素的高度以使其适合页面。当你在footer
中添加内容时,可以使用padding
来完善形状。
这些是唯一可能的选项。要么选择fixed
定位,要么选择absolute
定位。
margin-bottom
或 padding-bottom
以避免内容被“覆盖”在页脚下面 - 设置一个等于或大于页脚高度的值。 - Luca
#footer
放在了#page
里面,但是你想让它出现在 HTML 文档的最底部,是这样吗? - Zuul#page
和与#footer
相交的div
? - Zuul