滚动Scroll-Y不适用于Flexbox [英] overflow scroll-y not working with flexbox
问题描述
当新的div框(.dialog-box
)添加到父容器(.dialog-container
)时,我试图将div彼此堆叠".
I'm trying to "stack" divs on top of each other as new div boxes (.dialog-box
) are added to the parent container (.dialog-container
).
要堆叠元素,我在父对象上使用以下内容:
To stack the elements, I'm using the following on the parent:
display: flex;
flex-direction: column;
justify-content: flex-end;
我想滚动该容器以查找正在溢出的.dialog-box
,但是使用flex-box时,overflow-y: scroll;
不会滚动.
I'd like to scroll that container for .dialog-box
s that are overflowing, yet with flex-box the overflow-y: scroll;
is not scrolling.
两个框:(按预期从底部到顶部填充容器):
Two boxes: (fill up container from bottom to top as expected):
六个框(在容器的高度之外展开并应滚动):
Six boxes (expands outside the height of the container and should scroll):
SCSS:
.dialog-container {
border: 4px solid rgba(255, 255, 255, .4);
border-radius: 5px;
width: 300px;
height: 340px;
position: relative;
top: -50px;
margin: 0 auto;
overflow-y: scroll;
z-index: 5;
display: flex;
flex-direction: column;
justify-content: flex-end;
.dialog-box {
width: 90%;
background: $dialogBoxWhite;
margin-bottom: 20px;
border-radius: 8px;
border: 5px solid $dialogBoxGreenBorder;
color: $dialogBoxGreenFont;
text-align: center;
margin-left: 5px;
padding: 5px;
display: inline-block;
p {}
}
}
HTML:
<div class="dialog-container">
<div class="dialog-box"></div>
<div class="dialog-box"></div>
<div class="dialog-box"></div>
<div class="dialog-box"></div>
<div class="dialog-box"></div>
<div class="dialog-box"></div>
</div>
推荐答案
您只需删除 justify-content:flex-end;
两个框:(按预期从底部到顶部填充容器): 为此,您将以下代码添加到您的scss文件:
Two boxes: (fill up container from bottom to top as expected): for this you add below code to your scss file :
display: flex;
flex-direction: column-reverse;
justify-content: flex-start;
.dialog-container {
border: 4px solid rgba(0, 0, 0, .4);
border-radius: 5px;
width: 300px;
height: 350px;
position: relative;
margin: 0 auto;
overflow-y: scroll;
z-index: 5;
display: flex;
flex-direction: column-reverse;
justify-content: flex-start;
}
.dialog-box {
width: 90%;
background:white;
margin-bottom: 20px;
border-radius: 8px;
border: 5px solid green;
color: green;
text-align: center;
margin-left: 5px;
padding: 3px;
display: inline-block;
}
<div class="dialog-container">
<div class="dialog-box">Box 1</div>
<div class="dialog-box">Box 2</div>
<div class="dialog-box">Box 3</div>
<div class="dialog-box">Box 4</div>
<div class="dialog-box">Box 5</div>
<div class="dialog-box">Box 6</div>
<div class="dialog-box">Box 7</div>
</div>
这篇关于滚动Scroll-Y不适用于Flexbox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!