html代码为:
<div class="top"></div>
<div class="left-wrap">
<div class="nav"></div>
<div class="content">
<p class="title">1</p>
<p class="title">2</p>
<p class="title">3</p>
<p class="title">4</p>
<p class="title">5</p>
</div>
</div>
<div class="bottom"></div>
css为:
.top, .bottom {
height: 60px;
background: purple;
}
.left-wrap {
min-height: calc(100vh - 120px);
display: flex;
flex-direction: column;
background: #ccc;
width: 500px;
}
.nav {
height: 150px;
background: red;
}
.content {
flex: 1 1 0;
background: blue;
height: 400px;
overflow-y: auto;
}
.title {
height: 200px;
text-align: center;
}
效果为:
这个当时并不是要求的效果,需要将滚动条去掉,自动撑起高度,检查一遍原来代码问题就出现在这里:
原来flex有三个属性,flex-grow,flex-shrink,flex-basis,这里flex-shrink设置为1,当所设置的400px的高度支撑不起五个盒子的高度时,每个盒子会自动收缩,所以,不应该设置flex-shrink,只需要将flex: 1 1 0;改为flex: 1 0就可以了。
修改之后的效果为:
这样就达到效果了。