2010-03-26 61 views
0

我遇到的問題與我已絕對定位在頁面底部的頁腳有關。一切都很好,直到頁面上的副本開始向下延伸到頁面,然後導致我的內容井向下,向後延伸,頁腳。無論如何,我可以強制我的內容井將頁腳「推」下頁面?與相對和絕對定位有關的分區定位問題

下面是相關的html:

<div id="page"> 
     <div id="page_container"> 
     <div id="header"></div> 
     <div id="nav"></div> 
     <div id="main_content"> 
       <div id="left_column"></div> 
       <div id="right_column"></div> 
     </div> 
     </div> 
    </div> 
    <div id="footer"> 
    <div id="footer_container"> 
    </div> 
    </div> 

和有關CSS

#page   {width:100%;margin:0 0 10px 0; text-align:center;} 
#page_container {width:743px;height:auto !important;height:100%;margin:0 auto;min-height:100%;text-align:center;overflow:hidden;border:2px solid #000;} 
#header   {width:100%;background:url('../images/header.jpg');height:87px;clear:both; margin-top: -2px;} 
#nav    {width:100%;height:29px;float:left; text-align:left; border-bottom: solid 2px #000; border-top: solid 2px #000;} 
#main_content {width:100%;float:left; text-align:left; background-color:#fff; border-bottom: solid 2px #000; border-left: solid 2px #000; border-right: solid 2px #000;} 
#footer   {width:100%; position:absolute;margin-top:10px; bottom: 0; background:url('../images/footer_bg.jpg');height:133px;text-align:center;} 
#footer_container{width:746px;height:133px; text-align:left; display:inline-block;} 
#left_column  {width:230px; float:left; text-align:left; background-color:#fff; margin-top:5px;} 
#right_column {width:490px; float:right; text-align:left; background-color:#fff;margin-top:5px; padding:10px;} 

謝謝你也許可以給任何幫助!

回答

1

使用position: fixed;爲頁腳,您也可能想要爲您的body有一些padding-bottom,以便內容不會根據它。

+0

感謝reko但這並沒有改變頁腳行爲。我的主要內容仍然落後於頁腳。 – dparsons 2010-03-26 14:28:00

0

取出高度:100% on pageContainer - 將div固定爲窗口高度,而不是內容高度。

+0

嘿史蒂夫。感謝您的迴應,但這似乎沒有效果。當我縮小瀏覽器窗口以便文本向下展開時,內容仍然會落在頁腳後面。 – dparsons 2010-03-26 14:27:31

+0

你有沒有做過什麼與高度:自動部分?我不認爲這會做很棒的事情。 – stevedbrown 2010-03-26 14:52:26

0

試試這個:

<style type="text/css"> 
html, body { margin:0; padding:0; height:100%; }  
#page_container { width:743px; margin:0 auto; } 
#header { height:87px; border:1px solid #000; } 
#footer { height:133px; position:absolute; bottom:0; width:100%; border:1px solid #000;} 
#nav { height:29px; border:1px solid #000;} 
#left_column { width:230px; float:left; border:1px solid #000;} 
#right_column { width:490px; float:left; border:1px solid #000;} 

#page { min-height:100%; position:relative; } 
#main_content { padding-bottom:133px; } 
.clear { clear:both; } 
</style> 
<!--[if lt IE 7]> 
<style media="screen" type="text/css"> 
#container { 
    height:100%; 
} 
</style> 
<![endif]--> 

HTML(注意 - 你必須把#footer的內部#page這種方法工作):

<div id="page"> 
    <div id="page_container"> 
     <div id="header">hhhh</div> 
     <div id="nav">nav</div> 
     <div id="main_content"> 
      <div id="left_column">lll</div> 
      <div id="right_column">rrr</div> 
      <div class="clear"></div> 
     </div> 
    </div> 
    <div id="footer"> 
     <div id="footer_container">fffff</div> 
    </div>  
</div> 

您可以預覽在這裏工作的例子:http://www.front-end-developer.net/examples/bottomfooter/footer.htm

經過Chrome,Firefox,IE6,IE7,IE8和Opera測試。

+0

太棒了!但有一個問題:如何添加頂部邊距,以便頁面不會在瀏覽器窗口的頂部停留而不會導致滾動條出現?向任何容器(頁面,page_container,頁眉)添加頁邊距都會導致滾動條出現。謝謝! – dparsons 2010-03-27 01:38:21