1. 程式人生 > >CSS實現頭尾高度固定,中部內容百分百填充

CSS實現頭尾高度固定,中部內容百分百填充

效果圖:
這裡寫圖片描述

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <style type="text/css">
    * {
        padding: 0;
        margin: 0;
    }

    html {
        height: 100%;
    }

    body {
        height: 100%;
    }

    .container {
        height: 100%;
        position
: relative
; }
.header { height: 50px; width: 100%; top:0; background-color: red; position: absolute; } .content { width: 100%; background-color: lime; top:50px; bottom:50px; position: absolute; overflow
: auto
; }
footer{ width:100%; height:50px; position:absolute; bottom:0; background-color: red; }
</style> </head> <body> <div class="container"> <div class="header"> 這是標題 </div> <div
class="content">
<h1>diyige</h1> <h1>nihao</h1> <h1>nihao</h1> <h1>nihao</h1> <h1>nihao</h1> <h1>nihao</h1> <h1>nihao</h1> <h1>nihao</h1> <h1>nihao</h1> <h1>nihao</h1> <h1>nihao</h1> <h1>nihao</h1> <h1>nihao</h1> <h1>nihao</h1> <h1>nihao</h1> <h1>nihao</h1> <h1>nihao</h1> <h1>nihao</h1> <h1>nihao</h1> <h1>nihao</h1> <h1>nihao</h1> <h1>zuihoude</h1> </div> <footer> 這是腳註 </footer> </div> </body> </html>

而且這也是支援響應式的。