我该如何使用CSS或jQuery将
<div>
元素的定位设置在页面底部?position:absolute;bottom:0;
。<html>
<body>
<p>Some content</p>
<div class="footer">down there</div>
</body>
</html>
然后是以下的CSS
div.footer {
position: absolute;
bottom: 0;
right: 0;
}
该代码会将文本定位在您的视口(浏览器窗口)的右下角,滚动页面将移动页脚文本。
如果您使用
div.footer {
position: fixed;
bottom: 0;
right: 0;
}
top: 0
和 left: 0
来定位一个元素在左上角。position:fixed;
与bottom:0;
的组合对我有效。
我认为你可以做到这一点:
html{
min-height:100%;
position:relative;
background-color:red;
}
.footer{
bottom:0;
position:absolute;
background-color:blue;
}
<html>
<body>
<div class='footer'>
<h1>I am Footer</h1>
</div>
</body>
</html>
div
将会覆盖内容。想要解决这个问题,请参考这个例子:http://matthewjamestaylor.com/blog/bottom-footer-demo.htm - grant