<div id="wapper">
<div id="nofooter">
<div id="header">...</div>
<div id="content">...</div>
</div>
<div id="footer">...</div>
</div>
#wapper { position: relative; min-height: 100%; }
#nofooter { padding-bottom: 70px; } /* 關鍵行 */
#footer { position: absolute; bottom: 0; height: 70px; width: 100%; }
#wapper 設為 relative 定位基準,並保證最小高度 100% 撐開視窗。#footer 設為 absolute; bottom: 0 固定在視窗/容器底部,高度 70px。#nofooter(內容區容器)**無** padding-bottom: 70px,內容區底部會與 #footer 重疊,導致最後 70px 內容被 Footer 遮蓋不可見/不可點擊。padding-bottom: 70px 在內容區底部撐開 70px 空白區,Footer 絕對定位覆蓋此空白區,**視覺上 Footer 緊貼內容區底部,實際不遮擋內容**。| 方案 | 優點 | 缺點 |
|---|---|---|
| padding-bottom 預留 | 相容性極佳(IE6+)、無需 JS、結構簡單 | 需知 Footer 固定高度 |
Flexbox: body{display:flex;flex-direction:column;min-height:100vh} #content{flex:1} | 現代、自適應高度、無需魔術數字 | IE10+ 部分支援、舊專案遷移成本高 |
Grid: body{display:grid;grid-template-rows:auto 1fr auto} | 最語意化、兩維佈局強 | IE 不支援、需 Polyfill |
| JS 計算高度動態調整 | 適用動態 Footer 高度 | 需監聽 resize、效能稍差、JS 失效時佈局崩壞 |
@supports 降級。padding-bottom,並將 70px 定義為 CSS 變數 --footer-h 便於維護。理解「絕對定位 Footer + 內容區底部 Padding」經典模式,能快速解決固定底部導航/版權區遮蓋內容的通用問題。