在页面底部浮动DIV(它不应在页脚DIV后滚动)

时间:2011-11-26 08:33:43

标签: html css

div{
   position:fixed;
   bottom:0px;
   height:20px;
}
上面代码中的

解释了将始终保持DIV在底部。但我需要避免页脚后的滚动。我的意思是需要为浮动div设置边界。

你能帮助我吗?

  

[编辑]请参考这个并帮助我!   http://jsfiddle.net/umarfaruk/y9cWf/我添加了我的样本。怎么样   我可以在触摸页脚div时停止浮动div。 (我的意思是   浮动应该在页脚之前停止滚动)

更新:

谢谢你们。我在http://jsfiddle.net/PnUmM/1找到了解决方案。非常感谢@Gatekeeper :)

3 个答案:

答案 0 :(得分:1)

就像Giberno在他的评论中写道的那样,使用一个空的div来填充页脚所占用的空间(从而防止文本的最后一行被页脚隐藏。很简单:不需要脚本!

div#footer{
   position:fixed;
   bottom:0px;
   height:20px;
}

div#empty-space{
   height:20px; /* Same height as footer */
}

HTML:

Put your page here
...
<div id="empty-space"/>
<div id="footer">footer</div>

有关工作示例,请参阅此jsFiddle

答案 1 :(得分:1)

最简单的方法是给body底部填充与固定元素相同的高度。这样你就可以随时滚动到任何内容。

#body {
    padding-bottom: 50px;
}
#fixed {
    height: 50px;
    position: fixed;
    width: 100%;
}

here's a fiddle

答案 2 :(得分:0)

在页面或样式表中写入以避免在f

之后滚动条
* {
 margin: 0 auto;
}
相关问题