2011-12-05 18 views
2

我完全在瀏覽器窗口的底部放置一個頁腳,使用下面的代碼:絕對定位的div浮在主要內容

HTML

<html> 
    <body> 
     <div id="content"> 
      Content 
     </div> 
     <div id="footer"> 
      Footer 
     </div> 
    </body> 
</html> 

CSS

#content { 
    margin-bottom: 20px; 
    background: red; 
} 

#footer { 
    position: absolute; 
    bottom: 0; 
    width: 100%; 
    height: 20px; 
    background: blue; 
} 

這種方式和預期的一樣,但是當我使瀏覽器窗口變小時,真正涵蓋主要內容。什麼是防止這種情況的最有效方法?

在此先感謝。

+0

爲什麼你必須使用絕對定位你的頁腳? – mc10

+0

@ mc10我使用絕對定位,因爲我想讓頁腳「粘」到瀏覽器窗口的底部。 – Jonathan

+0

如何在'#content'中添加一個'z-index'? – mc10

回答

0

試試這個:

#content { 
    padding-bottom: 20px; 
    background: red; 
} 

#footer { 
    position:fixed; //Changed to fixed 
    bottom:0px; 
    width:100%; 
    height: 20px; 
} 
+0

謝謝@Jon。我不能但得到這個工作:http://jsfiddle.net/2Afs6/ – Jonathan

相關問題