我花了很多年试图使用CSS将页脚粘到页面底部,并且刚刚放弃。jQuery将页脚粘贴到页面底部
我想要的是,如果视口的高度小于HTML文档的高度,页脚就不会分配额外的CSS属性。
如果原稿的高度小于窗口的高度,我想分配到DIV#thefooter以下CSS:
position: fixed;
bottom: 0px;
margin-left: -5px;
因此,这里是我的JS代码。它什么都不做,控制台日志什么也没有显示。
$(document).ready(function(){
$(window).bind("load", function(){ putFooter(); });
$(window).resize(function(){ putFooter(); });
function putFooter(){
var wh = $(window).height();
var dh = $(document).height();
if(dh < wh) {
$("#thefooter").css({"position": "fixed", "bottom": "0px", "margin-left": "-5px"});
}
}
});
编辑:这是我的HTML是什么样子:
<div id="allexceptfooter">
<div id="themenu">...</div>
<div id="actualcontent">...</div>
</div>
<div id="thefooter">...</div>
如果你想看到整个事情我的网站是duncannz .COM
你可以通过使用一个对象'.css({“position”:“fixed”,“bottom”:“0px”,“ margin-left“:”-5px“})' – Andreas
@安德烈亚斯感谢编辑 – stackunderflow
这只是意味着对未来的暗示:D – Andreas