我正在编写一个页面底部带有固定页脚的网页。页面的内容具有特定的宽度并居中。页脚也有特定的宽度并且必须居中。
问题:
- 我无法使用
postiton: fixed
- 页脚未居中 - 页面内容是从数据库动态加载的,所以我不知道确切的高度
- 如果浏览器窗口非常小,页脚会碰到内容并将其覆盖。A
z-index
几乎无法修复它,因为我在背景设置上设置了渐变,就像身体背景一样。
所以我需要类似float: bottom
......
我正在编写一个页面底部带有固定页脚的网页。页面的内容具有特定的宽度并居中。页脚也有特定的宽度并且必须居中。
问题:
postiton: fixed
- 页脚未居中z-index
几乎无法修复它,因为我在背景设置上设置了渐变,就像身体背景一样。所以我需要类似float: bottom
......
尽管其他答案确实有效,但您应该避免使用负边距。
尝试这个:
.footerholder {
background: none repeat scroll 0 0 transparent;
bottom: 0;
position: fixed;
text-align: center;
width: 100%;
}
.footer {
background: none repeat scroll 0 0 blue;
height: 100px;
margin: auto;
width: 400px;
}
HTML 将是:
<div class="footerholder">
<div class="footer">
....
</div>
</div>
- - - - - 编辑 - - - - - -
您还应该修改整个页面大小,以考虑页脚的高度 - 否则您将永远看不到底部内容
.footer{
position:fixed;
bottom:0;
left:50%;
margin-left:-200px; /*negative half the width */
background:red;
width:400px;
height:100px;
}