2011-04-28 63 views
1

如果內容大於一頁,我正在尋找將頁腳設置爲頁面結尾或內容結束的可能性。 我不想有一個固定頁腳的內容是可滾動的。 我不知道這是否可能。將頁腳設置爲內容或頁面結尾

所以,這是我的代碼。 class =「div1」的div包含內容。 內容包含內容以及頁腳。


<div class="div1"> 
    <div class="content"> 
     <div class="myContent"></div> 
     <div class="myContent"></div> 
     <div class="myContent"></div> 
     <div class="footer"></div> 
    </div> 
</div> 

頁腳的高度爲50px。 我的問題如下: 如果我有一個屏幕高度:500px,內容只有150px高,頁腳被設置在class =「myContent」的最後一個div元素之後。 它應該設置爲頁面的結尾,就像我通過

 
bottom:0;position:fixed
收到的效果一樣。但是,如果內容高度爲600px,則應該在class =「myContent」的最後一個div後面設置頁腳。這裏不需要任何樣式。

你知道如何解決它嗎?

回答

1

你的意思是Make the Footer Stick to the Bottom of a Page? 或本one

的CSS

html, body {height: 100%;} 

#wrap {min-height: 100%;} 
#main {overflow:auto; 
padding-bottom: 150px;} /* must be same height as the footer */ 

#footer {position: relative; 
margin-top: -150px; /* negative value of footer height */ 
height: 150px; 
clear:both;} 

和HTML

<div id="wrap"> 

    <div id="main"> 

    </div> 

</div> 

<div id="footer"> 

</div> 
+0

+1。我確實相信她的確如此。這是一篇很好的文章。 – 2011-04-28 13:10:56

+0

嗨,對不起,我遲到了。不幸的是我的html是不同的。 :-(footer div在主div中,你的例子在我的情況下不起作用......這就是我問的原因。 – judi55 2011-04-28 15:44:07

+0

然後將你的頁腳移出主界面或者創建一個新的div。這是你需要改變它以滿足你的確切需要的一個例子 – yossi 2011-04-28 17:26:17

1

我想這可能會幫助你擺脫掉這個問題:

.footer {position:absolute;left:0;right:0;bottom:0;background:green;height:50px} 

這樣可以解決目標:

<div style="position:absolute"> 
    <div style="position:absolute"> 
     <div id="top" style="height:50px;width:100%;position:fixed;left:0;top:0;background:red"> content 1 </div> 
     <div id="middle" style="background:green;position:fixed;top:50px; left:0;bottom:50px;right:0">content 2 </div> 
     <div id="middle" style="background:blue;position:fixed;top:100px; left:0;bottom:50px;right:0">content 3 </div> 
     <div id="bottom" style="height:50px;width:100%;position:fixed;left:0;bottom:0;background:orange">Footer</div> 
    </div> 
</div> 
+0

嗨,它不工作,因爲有人已經設置了位置:在父母divs絕對 - 在某個地方,謝謝你,這是值得一試 – judi55 2011-04-28 15:48:46

+0

@ judi55大家好,請檢查一下新的答案,如果沒有,請評論我有什麼問題,在這裏,我爲所有父'div'使用'position:absolute',如果任何一個'div'具有'position:absolute 「我認爲這也會起作用。 – thecodeparadox 2011-04-30 08:36:53