WEB前端-HTML-CSS-後臺管理頁面佈局小例
阿新 • • 發佈:2019-01-23
作為一個後臺管理頁面,不必太過複雜,一般只需要三部分:
1、上層標籤塊;
2、左側選單塊;
3、中部內容顯示塊;
今天簡要給大家分享一個佈局中的一個小case;
需求:要求上層標籤塊、左側選單快固定不動,滾動條只對中部顯示塊作用;
其實很簡單,就是利用absolute的底部定位 ”bottom:0“配合overflow:auto來實現的。
程式碼如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title >
<style>
body{
margin:0 auto;
background-color:greenyellow;
}
.pa-header{
height:48px;
background-color:blue;
}
.pa_body .body-menu{
position:absolute;
top:48px;
left :0;
bottom:0;
width:200px;
background-color:red;
}
.pa_body .body-content{
position:absolute;
top:48px;
left:210px;
right:0;
background-color:green;
bottom:0;
/* “bottom:0 與 overflow” 結合使用的效果:當內容超出顯示器時,自動新增本區域的滾動條,其他區域保持不變*/
overflow:auto;
/*除了上面的方式,還有一種是不定義bottom,也不用overflow,這樣內容是多少,中間內容區的行高就是多少,自適應,但是選單和標題欄就會隨著滾輪而動*/
}
</style>
</head>
<body>
<div class="pa-header">top-target</div>
<div class="pa_body">
<div class="body-menu"></div>
<div class="body-content">
1111111111111111111111111111111111<br/>
<div style="border:2px dashed wheat;height:60px;"></div>
2222222222222222222222222222222222<br/>
<div style="border:2px dashed wheat;height:60px;"></div>
2222222222222222222222222222222222<br/>
<div style="border:2px dashed wheat;height:60px;"></div>
2222222222222222222222222222222222<br/>
<div style="border:2px dashed wheat;height:60px;"></div>
2222222222222222222222222222222222<br/>
<div style="border:2px dashed wheat;height:60px;"></div>
2222222222222222222222222222222222<br/>
<div style="border:2px dashed wheat;height:60px;"></div>
2222222222222222222222222222222222<br/>
<div style="border:2px dashed wheat;height:60px;"></div>
2222222222222222222222222222222222<br/>
2222222222222222222222222222222222<br/>
<div style="border:2px dashed wheat;height:60px;"></div>
2222222222222222222222222222222222<br/>
<div style="border:2px dashed wheat;height:60px;"></div>
2222222222222222222222222222222222<br/>
2222222222222222222222222222222222<br/>
<div style="border:2px dashed wheat;height:60px;"></div>
2222222222222222222222222222222222<br/>
<div style="border:2px dashed wheat;height:60px;"></div>
2222222222222222222222222222222222<br/>
2222222222222222222222222222222222<br/>
<div style="border:2px dashed wheat;height:60px;"></div>
2222222222222222222222222222222222<br/>
<div style="border:2px dashed wheat;height:60px;"></div>
2222222222222222222222222222222222<br/>
</div>
</div>
</body>
</html>