HTML – 强制页脚停留在底部?

前端之家收集整理的这篇文章主要介绍了HTML – 强制页脚停留在底部?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我没有容器,也没有包装器.

我只是有这样的布局……

  1. <body>
  2.  
  3. <div id="header">
  4. </div>
  5.  
  6. <div id="left">
  7. </div>
  8.  
  9. <div id="right">
  10. </div>
  11.  
  12. <div class="clear"></div>
  13.  
  14. <div id="footer">
  15. </div>

我想要做的是确保页脚总是停留在屏幕的底部,无论我的内容是否相当远,甚至没有足够的内容一直到屏幕的底部.

到目前为止,我可以通过上面列出的两种方式工作,但我希望两者都有效.

这是我为此设置的CSS.

  1. html {
  2. height: 100%;
  3. }
  4.  
  5. body {
  6. height: 100%;
  7. position: relative;
  8. }
  9.  
  10. #footer {
  11. position: absolute;
  12. bottom: 0;
  13. }

我知道如果我应用最小高度:100%;到CSS文档中的HTML元素将随着内容的推移而去,但如果我没有任何内容,它本身就不会粘在屏幕的底部.决议无论如何

我多次遇到这个问题,从来不确定如何解决这个问题.所以,一些帮助将得到很多赞赏,以及一些解释.

非常感谢大家的帮助!

解决方法

使用这个配合,这是一个非常好解释和易于遵循的教程:

http://code.google.com/p/cleanstickyfooter/

最好的粘性页脚真的非常好用

从网站引用(我完全同意):

The Difference

Google “sticky footer”,I have listed below why this technique works
better than the top results from this search.

07001 – This technique is similar,but
cleanStickyFooter takes it much further. The technique located here
doesn’t play nicely when you want to make your footer have a width of
100%.

07002 – This technique is one out of many I am referring to when I say its invasive with CSS clearing hacks.

猜你在找的HTML相关文章