定位一个停留在底部的<div>元素

3
我该如何将一个
元素放置在页面底部,即使我滚动页面它也会保持在那里?这可以只使用CSS完成,还是需要同时使用jQuery?DEMO
3个回答

7

请注意,position: fixed 不受 IE 6 或许多移动浏览器(包括 Mobile Safari)的支持。 - eyelidlessness

2
你可以使用固定定位来设置你的
元素:
div.footer {
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;   
    height: 100px;     
    /* etc. */
}

1

在你的“页脚”div上使用position: fixed,并在body中添加padding-bottom: 50px(与你的“页脚”div相同的高度),这样当你滚动到底部时,不会隐藏任何内容:

参见:http://jsfiddle.net/gyExR/19/

body {
    padding-bottom: 50px
}
div {
    position: fixed;
    ..
}

浏览器支持: http://caniuse.com/css-fixed


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接