4

我正在编写一个页面底部带有固定页脚的网页。页面的内容具有特定的宽度并居中。页脚也有特定的宽度并且必须居中。

问题:

  1. 我无法使用postiton: fixed- 页脚未居中
  2. 页面内容是从数据库动态加载的,所以我不知道确切的高度
  3. 如果浏览器窗口非常小,页脚会碰到内容并将其覆盖。Az-index几乎无法修复它,因为我在背景设置上设置了渐变,就像身体背景一样。

所以我需要类似float: bottom......

4

2 回答 2

14

尽管其他答案确实有效,但您应该避免使用负边距。

尝试这个:

.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>

- - - - - 编辑 - - - - - -

您还应该修改整个页面大小,以考虑页脚的高度 - 否则您将永远看不到底部内容

于 2011-04-07T21:35:00.033 回答
6
.footer{
    position:fixed;
    bottom:0;
    left:50%;
    margin-left:-200px; /*negative half the width */
    background:red;
    width:400px;
    height:100px;
}

在http://jsfiddle.net/qdVbR/检查工作示例

于 2011-04-07T21:20:45.443 回答