gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 14:59:16 25 4
gpt4 key购买 nike

所以我有一个页脚:

<div id="footer" >
<div style="padding:20px;">
Footer
</div>
</div>

包装器中的样式:

#page { width:964px; margin:0 auto; }

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

position:absolute;
bottom:0;

之前的一些div与footer相交,我还需要自己设置高度和宽度。

demo

最佳答案

像这样尝试..

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 */
}

HTML

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

<div class="footer">
<p>footer text here.</p>
</div>

关于html - 如何在没有绝对的情况下将div附加到底部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11042064/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com