2014-01-24 101 views
1

动态粘我有问题,我的XHTML页面页脚的HTML页面...我希望把页脚总是在页面的结束,在它的底部,所以,当页面内容很差,页脚会粘在屏幕的底部,但是当页面长得多时,它会在页面的最后内容之后粘到页面上。页脚对底部

我该怎么做?

这是我的CSS文件

html { 
    height:98%; 
    margin: 0 auto 0 auto; 
    width:1280px; 
    padding:2px; 
    padding-bottom:0px; 
} 

body { 
    overflow:auto; 
    width:100%; 
    margin: 0 auto 0 auto; 
    height:100%; 
} 

#container { 
    min-height:100%; 
    height:100%; 
    margin:0 auto -50px; 
} 

#box { 
    min-height:100%; 
} 

#push { 
    height:50px; 
    clear:both; 
} 

#footer { 
    height:50px; 
    clear:both; 
    position:relative; 
    bottom:0px; 
    width:100%; 
} 

而且我的网页

<html> 
    <h:head></h:head> 
    <h:body> 
     <div id="conatiner"> 
     <div id="box"> 
      <header></header> 
      <div id="externalborder"> 
      <div id="push"></div> 
      <div id="footer"></div> 
     </div> 
     </div> 
    </h:body> 
</html> 
+2

[使页脚正确粘贴到页面底部]的可能的副本(http://stackoverflow.com/questions/3443606/make-footer-stick-to-bottom-of-page-correctly) –

+0

您是否必须支持最终版本的IE?你可以使用'计算的()' – DaniP

+0

它不是一个重复的,因为在其他职位的要求是不同的那种....我不得不使用它主要是Chrome和Firefox,我怎么能使用计算()? – RevivedPicard

回答

1

的U此结构简单得把底部的0像素,并设置位置固定在页脚。 实施例:

#footer { 
    position:fixed; 
    bottom:0px; 
} 

#container { 
    padding-bottom:3em; 
} 
+0

*但是当一个页面长得多时,它会在最后一页粘贴*固定后不能以这种方式工作 – DaniP

+0

是的固定它不工​​作,我想要的方式......固定它会坚持在视图页面的末端,如果页面较长页脚将ovverlap内容... – RevivedPicard

0

当文档高度大于视口时,就可以再切换页脚静态定位。这使你在视口的底部定位页脚内容时,短的能力,并在页面的结尾为正常时的内容很长。

您将需要使用JavaScript来检测时,内容高度大于视口更大,并添加改变页脚静态定位的风格。

+0

我怎样才能做到这一点????没有JavaScript有一个方法?我不知道javascript XD – RevivedPicard

+1

@ user3220773看看这个非JS方法http://matthewjamestaylor.com/blog/keeping-footers-at-the-bottom-of-the-page –