如何让页脚停留在网页的底部?

2023-11-26

我有一个简单的 2 列布局,其中的页脚可以清除标记中的左右 div。我的问题是我无法让页脚在所有浏览器中保留在页面底部。如果内容将页脚向下推,它就会起作用,但情况并非总是如此。


要获得粘性页脚:

  1. Have a <div> with class="wrapper"为您的内容。

  2. Right before闭幕式</div> of the wrapper放置<div class="push"></div>.

  3. Right after闭幕式</div> of the wrapper放置<div class="footer"></div>.

* {
    margin: 0;
}
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 */
}
<div class="wrapper">wrapper
    <div class="push">push</div>
</div>
<div class="footer">footer</div>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何让页脚停留在网页的底部? 的相关文章

随机推荐