Skip navigation.

极湖

无不用其“极”

用 CSS 实现 footer 的位置固定

,

在网上找到很多解决方案,觉得这个网站介绍的方法最省事: http://ryanfait.com/sticky-footer/

实现方法简单说明如下:

首先,HTML要有以下内容
<body>
    <div class="wrapper">
        <!--
        网页内容
        -->
        <div class="push">
        </div>
    </div>

    <div class="footer">
    </div>
</body>
其次,CSS要这样写
html, body {
    height: 100%;
}

.wrapper {
    min-height: 100%;
    height: auto !important;
    height: 100%; /* 为了兼容IE */
    margin: 0 auto -100px; /* 下部空余为 class="footer" 同样高度的负值 */
}

.footer,
.push {
    height: 100px;
}

注意点:
如果没有「div class="wrapper"」,Opera下「class="footer"」和「div class="wrapper"」将会重叠显示。

中文与编码通过 Subversion 的 hook 自动更新代码

Write a comment

You must be logged in to write a comment. If you're not a registered member, please sign up.

December 2009
S M T W T F S
November 2009January 2010
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31