CSS布局那些事儿
浏览许多开源项目的学习网站时,会经常看到它们网页布局是这样子的:顶部固定不动,左侧目录栏可以滚动,右侧内容栏也可以滚动,目录栏的滚动与内容栏互不影响。于是,写个demo模仿这样的布局,具体如下:
效果:
特点:
顶部固定,左右两块内容独立,当左右两块的内容超出浏览器高度时可以各自滚动,互不影响。
完整代码:
- html
<div id="app">
<div class="header">header</div>
<div class="main">
<div class="content">content</div>
<div class="aside">
<div class="aside-content">aside</div>
</div>
</div>
</div>
- css
html, body, #app{
width: 100%;
height: 100%;
}
body{
padding: 0;
margin: 0;
}
#app{
background: #f3e1e1;
}
.header{
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 56px;
color: #fff;
background: #000;
}
.main{
overflow: scroll;
width: 1000px;
height: calc(100% - 56px);
padding-top: 56px;
margin: 0 auto;
background: red;
}
.content{
padding-left: 150px;
height: 1000px;
background: #2196f3;
}
.aside{
position: fixed;
top: 0;
bottom: 0;
overflow: scroll;
width: 150px;
margin-top: 56px;
background: #cddc39;
}
.aside-content{
width: 100%;
height: 1000px;
}