我将尝试为一个高度动态增长的div设置一个粘性底部。该div需要浮动在页面中央(距离左右两侧相同)。
以下是我所拥有的HTML代码(已去除无关内容):
以下是相关的 CSS (已去除无关部分):
以下是我所拥有的HTML代码(已去除无关内容):
<html>
<body>
<div class="bodybackground">
<div class="container"><!-- floats in the middle -->
<div class="mainContainer"><!-- different color etc -->
<!-- content with dynamic height -->
</div>
<footer class="pagefooter"></footer>
</div>
</div>
</body>
</html>
以下是相关的 CSS (已去除无关部分):
html {
height: 100%;
margin: 0px;
padding: 0px;
}
body {
margin: 0px;
height: 100%;
}
.bodybackground {
height: 100%;
min-height: 100%;
}
.container {
min-height: 100%;
display: inline-block; /* needed make it float in the middle of body */
top: 0px;
position: relative;
padding: 0px;
padding-bottom: 158px; /* height of footer */
}
.mainContainer {
position: absolute;
height: 100%;
overflow: auto;
}
.pagefooter {
position: absolute;
bottom: 0px;
margin: 0px;
padding: 0px;
height: 158px;
}
的内容会漂浮到页脚后面,而不是页脚在页面最底部。我尝试了各种方法,除了那些要求我更改容器的display属性的示例,因为我需要它保持在中间漂浮。
有什么线索可以帮助我解决问题吗?谢谢!
我需要再调整一下.push,但这解决了问题!感谢您的快速回答!