[英]Making the footer stick at the bottom of the page
我真正想要的是在页面其余部分滚动时使页脚位于页面底部。 我没有一个令人满意的答案。 因此,请有人帮助。
编辑
实际上,我正在使用javascript动态修改body的DOM元素。 因此,我没有一个名为“ content”的div。 即我的HTML文件的结构将是这样的:
<body>
---- body -----
<div id="footer">
My Dynamic Footer
</div>
</body>
#footer {
position: fixed;
bottom: 0;
left: 0;
}
position: fixed;
是您唯一的解决方案, 请参见此演示
CSS
html, body, #container {
height: 100%;
margin:0;
padding:0;
}
#footer {
position: fixed;
bottom: 0;
left: 0;
z-index: 10;
height: 3em;
width:100%;
background-color:grey;
}
HTML
我的动态页脚
注意 :在小提琴中,取消注释文本以查看在动态设置高度后页脚会拉伸高度!!
==========================编辑======================= ===
根据您的评论,这是更新的小提琴
======================================================================================= ====
使用jQuery就可以实现目标...... 看到小提琴
需要JQ:
$( "<div class='space'></div>" ).insertBefore( "#footer" );
CSS
html, body {
height: 100%;
margin:0;
padding:0;
}
.space
{
height:6em; /* this is problem solver */
}
#footer {
position: fixed;
bottom: 0;
left: 0;
z-index: 10;
height: 3em;
width:100%;
background-color:grey;
}
==========================使用JAVASCRIPT的最终编辑==================== ======
保持以上HTMl标记不变,请使用以下javascript来解决您的问题:
var link = document.getElementById("footer")
var new_node = document.createElement("div");
new_node.className="space";
new_node.innerHTML = "";
link.parentNode.insertBefore(new_node, link.nextSibling);
我要添加的一件事是在页margin-bottom
以便页脚到达页面底部时不会隐藏任何内容。
.content {
margin-bottom: 200px;
}
footer {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
height: 200px;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.