css頁面布局,實現內容部分自適應屏幕,當內容高度小於瀏覽器窗口高度時,頁腳在瀏覽器窗口底部;當內容高度高於瀏覽器窗口高度時,頁腳自動被撐到頁面底部。
<style type="text/css"> * { margin: 0; padding: 0; box-sizing: border-box; } html, body { width: 100%; height: 100%; } .main { overflow: hidden; position: relative; min-height: 100%; background: #eee; } .red { margin-bottom: 50px; height: 200px; background: #f00; } .footer { position: absolute; bottom: 0; left: 0; height: 50px; width: 100%; background: #0f0; } </style> <body> <div class="main"> <div class="red"></div> <div class="footer"></div> </div> </body>
