【问题标题】:how to make flex items scrollable with overflowing content, column如何使用溢出的内容,列使弹性项目可滚动
【发布时间】:2018-07-06 13:07:30
【问题描述】:
我有一支笔,是我收集起来的。我有一个面板部分,里面有方形 div,有一个列方向,但由于某种原因,我无法使该面板部分可滚动以容纳内部有高度的 div。我尝试了溢出-y:自动,但它的行为并不正常。现在盒子只是缩小到适当的位置。
.panel-section {
flex-basis: 18vw;
background-color: #BFFD19;
padding-top: 15px;
padding-left: 15px;
padding-right: 30px;
min-height: 0px;
display: flex;
flex-direction: column;
.thumbnail-holder {
margin-bottom: 15px;
background-color: #6036AD;
width: 95%;
height: 160px;
}
}
}
https://codepen.io/anon/pen/OzKKgy
面板部分(右侧)和框是缩略图支架。
我读过其他关于溢出的文章,但这些技术对我不起作用。
【问题讨论】:
标签:
css
responsive-design
flexbox
overflow
【解决方案1】:
要使.panel-section 可滚动,请将overflow: auto 添加到其规则中。
然后,作为弹性项目的默认flex-shrink 值是1,这意味着它被设置为收缩以适应它的父项,添加flex-shrink: 0 .thumbnail-holder,然后他们将保持他们的高度。
此外,还有一个修复程序,即 i.a.火狐需要的,就是在.top-section上设置min-height: 0;,让它比它的内容还小。
注意,为了避免视口上出现垂直滚动条,并且更容易看到.panel-section 上的滚动条,我将modal-content 元素上的内联样式更改为width:100%(% 而不是@987654334 @)。
Updated codepen
堆栈sn-p
.modal-content {
display: flex;
flex-direction: column;
}
.modal-content .top-section {
background-color: #2EC55C;
flex-grow: 1;
min-height: 0;
display: flex;
}
.modal-content .top-section .content-section {
flex-grow: 1;
background-color: #6733FC;
display: flex;
flex-direction: column;
}
.modal-content .top-section .content-section .title-section {
background-color: #21DE71;
flex-basis: 10vh;
}
.modal-content .top-section .content-section .beer-section {
background-color: #FA64FF;
flex-grow: 1;
display: flex;
}
.modal-content .top-section .content-section .beer-section .image-section {
background-color: #90FF00;
flex-basis: 50%;
display: flex;
align-items: center;
justify-content: center;
}
.modal-content .top-section .content-section .beer-section .image-section .image-container {
background-color: #FBA02B;
height: 72vh;
width: 55vh;
}
.modal-content .top-section .content-section .beer-section .text-section {
background-color: #F63333;
flex-basis: 50%;
}
.modal-content .top-section .panel-section {
flex-basis: 18vw;
background-color: #BFFD19;
padding-top: 15px;
padding-left: 15px;
padding-right: 30px;
min-height: 0px;
display: flex;
flex-direction: column;
overflow: auto;
}
.modal-content .top-section .panel-section .thumbnail-holder {
margin-bottom: 15px;
background-color: #6036AD;
width: 95%;
height: 160px;
flex-shrink: 0;
}
.modal-content .bottom-section {
background-color: #4283FA;
flex-basis: 10vh;
}
@media (max-width: 1100px) {
.modal-content .top-section .panel-section {
flex-basis: 25vw;
}
}
@media (max-width: 450px) {
.modal-content .top-section .panel-section {
display: none;
}
}
<div class="modal-content" style="height:100vh;width:100%;">
<div class="top-section">
<div class="content-section">
<div class="title-section">
</div>
<div class="beer-section">
<div class="image-section">
<div class="image-container">
</div>
</div>
<div class="text-section">
</div>
</div>
</div>
<div class="panel-section">
<div class="thumbnail-holder">
</div>
<div class="thumbnail-holder">
</div>
<div class="thumbnail-holder">
</div>
<div class="thumbnail-holder">
</div>
<div class="thumbnail-holder">
</div>
</div>
</div>
<div class="bottom-section">
</div>
</div>