那麼如何將Web頁面的 「footer」部分永遠固定在頁面的底部呢?(注意了這裏所說的是頁腳footer永遠固定在頁面的底部,而不是永遠固定在顯示器屏幕的底部)html
就是當內容只有一點點時,Web頁面顯示在瀏覽器底部,當內容高度超過瀏覽器高度時,Web頁面的footer部分在頁面的底部,總而言之Web頁面的footer部分永遠在頁面的底部,也就是,Footer部分永遠沉底。瀏覽器
1. HTML結構:code
<div id="container"> <div class="content"> <ul> <li>內容</li> </ul> <div class="footer"></div> </div> </div>
2. CSS代碼:htm
* { padding: 0; margin: 0; list-style: none; } html, body { height: 100%; } #container { height: 100%; background-color: red; overflow-x: hidden; } .content { position: relative; min-height: 100%; background-color: yellow; padding-bottom: 70px; box-sizing: border-box; } .footer { position: absolute; left: 0; bottom: 0; width: 100%; height: 70px; background-color: blue; } <div class="container"> <div class="content"> <ul> <li>內容</li> </ul> <div class="footer"></div> </div> </div>