<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
body{
/*去掉最顶部间距*/
margin: 0;
}
.left{
float: left;
}
.right{
float: right;
}
.pg-header{
height: 48px;
background-color: #2459a2;
color: white;
}
/*左侧菜单跟随滚动条*/
.pg-content .menu{
/*absolute定位会随着滚动条滑动而滑动,fixed不会随滚动条滑动而滑动,relative单独使用没用*/
position: absolute;
top:48px;
left: 0;
bottom: 0;
width: 200px;
background-color: #dddddd;
}
.pg-content .content{
/*使用absolute,当内容较多时,一屏之后的数据就没有背景色,可将该内容用一个div包裹起来加背景色解决*/
position: absolute;
top: 48px;
right: 0;
bottom: 0;
left: 200px;
/*当屏幕缩小到最小宽度后会出现滚动条滑动查看横向内容*/
min-width: 500px;
/*background-color: purple;*/
/*加了overflow: auto;后当内容太多时会出现滚动条,当 position: absolute;时加了overflow: auto;左侧菜单及header
不跟随滚动条滚动,不加就跟随滚动条滚动*/
overflow: auto;
}
</style>
</head>
<body>
<div class="pg-header"></div>
<div class="pg-content">
<div class="menu left">q</div>
<div class="content left">
<div style="background-color:purple;">
<p style="margin: 0">hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p>
<p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p>
<p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p>
<p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p>
<p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p>
<p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p>
<p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p>
<p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p>
<p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p>
<p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p>
<p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p><p>hhh</p>
</div>
</div>
</div>
<div class="pg-footer"></div>
</body>
</html>
当position: absolute;时加了overflow: auto;header及左侧菜单不跟随滚动条滚动,不加就跟随滚动条滚动,所以可通过overflow: auto;来控制两种模式