2014-01-24 104 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 –