如何在没有绝对的情况下附加div到底?

NoN*_*meZ 6 html css css3

所以我有一个页脚:

<div id="footer" >
    <div style="padding:20px;">
        Footer
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

哪个是样式包装:

#page { width:964px; margin:0 auto; }
Run Code Online (Sandbox Code Playgroud)

所以我需要将页脚div附加到浏览器的底部.问题是如果我添加:

position:absolute;
bottom:0;
Run Code Online (Sandbox Code Playgroud)

一些前面的div与页脚相交,我也需要自己设置高度和宽度.

演示

CSS*_*Guy 7

试试这样..

CSS

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 */
}
Run Code Online (Sandbox Code Playgroud)

HTML

<div class="wrapper">
    <p>wrapper text here</p>    
    <div class="push"></div>
</div>

<div class="footer">
    <p>footer text here.</p>
</div>
Run Code Online (Sandbox Code Playgroud)


Luc*_*uca -1

使用:

#footer {
    position: fixed;
    bottom: 0;
}
Run Code Online (Sandbox Code Playgroud)

这是一篇很好的文章,可以帮助您了解position:其工作原理