2015-09-20 65 views
1

我想讓我的內容與容器div一起展開,但取而代之的是它被切斷。獲取內容滾動頁面的其餘部分

這裏是我的HTML代碼:

<div id="container"> 
<section> 
Lots of content goes here 
</section> 
</div> 
<div class="footer">Footer Content</div> 

我的CSS代碼:

html { 
    min-height: 100%; 
    position: relative; 
} 

body { 
    width: 100%; 
    height: 100%; 
    background: #ECECEC; 
    overflow: auto; 
} 

#container { 
    width: 80%; 
    margin: 0 auto; 
    background: white; 
    height: 100vh; 
} 

section { 
    overflow: auto; /* Trying to make content scrollable */ 
} 

.footer { 
      width: 100%; 
      position: absolute; 
      left: 0; 
      bottom: 0; 

} 

頁腳底部出現重疊內容的一部分。我一直在尋找答案,看起來頁腳的位置可能會導致這個問題。有沒有一種方法可以讓容器在容器div中展開,並且在我的情況下繼續將頁腳放在底部?

+0

聊天后發佈最終答案 – Musa

回答

1

有兩個問題與CSS:

  1. 您應該使用min-height: 100vh;#container。這表示身高至少應該是'100vh',如果需要,身高應該會增長。
  2. 對於.footer,您應該使用position: fixed;。這將確保頁腳保持在該位置,而不管頁面的垂直滾動。
+0

即使發生了變化,頁腳仍然會被推到內容上。 – freetoplay

+0

@ dtrinh100對不起。您應該在父級上設置'overflow:scroll'。我將更新答案 – Musa

+0

這會在內容部分添加一個滾動條,但我只希望用戶使用默認的瀏覽器滾動條。有沒有辦法做到這一點?另外,一些內容仍然被切斷。 – freetoplay