【发布时间】:2019-05-14 00:37:05
【问题描述】:
我有以下布局,它是一个包装器(内容),其中包含一些其他 div,这些 div 也具有一些 flex 属性。
从以下链接可以看出,内容中的 div 现在随着内容的大小而放大。
.content {
width: 100%;
height: 400px;
display: flex;
overflow: auto;
background-color: blue;
}
.a {
width: 165px;
height: 100%;
flex-grow: 1;
background-color: red;
}
.b {
width: 65px;
display: flex;
padding-top: 20px;
padding-bottom: 20px;
justify-content: center;
background-color: yellow;
height: 100%;
}
.c {
width: 165px;
flex-grow: 1;
margin-right: 15px;
background-color: green;
height: 100%;
}
<div class="content">
<div class="a">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing
software like Aldus PageMaker including versions of Lorem Ipsum. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took
a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets
containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
<div class="b">
<div class="separator">
s
</div>
</div>
<div class="c">
c
</div>
</div>
我想要实现的目标: - 红色、黄色、绿色 div 的高度应该与蓝色(内容)div 相同,因此在滚动时您看不到底部的蓝色部分
如何做到这一点?我的代码有什么问题?
我只支持最新的 chrome,我可以使用 CSS3
【问题讨论】:
-
删除容器上的
overflow: auto并在.b类上添加box-sizing: border-box,这样您的填充不会使其溢出容器。看看这个,codepen.io/Tan007/pen/joMqYM