我试图"堆叠"当新的div框(.dialog-box
)被添加到父容器(.dialog-container
)时,div彼此重叠。
要堆叠元素,请在父级上使用以下内容:
display: flex;
flex-direction: column;
justify-content: flex-end;
我想滚动那个溢出的.dialog-box
容器,但是使用flex-box overflow-y: 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>
答案 0 :(得分:1)
您只需删除 justify-content:flex-end;
两个框:(按预期从底部到顶部填充容器): 为此,您将以下代码添加到您的scss文件:
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>
中显示示例
答案 1 :(得分:-2)
更新答案,我混淆了flex-direction的值。
'row'右边不是'column'
在.dialog-container
中添加cssflex-direction: row;
flex-wrap : wrap;
或
flex-flow: row wrap
答案 2 :(得分:-3)
尝试将display: flex;
更改为display: flex-box;
这将为您提供实际滚动的滚动条。此外,您的示例div都缺少结束标记。
https://jsfiddle.net/Lpw0726j/23/
<div class="dialog-container">
<div class="dialog-box">9</div>
<div class="dialog-box">8</div>
<div class="dialog-box">7</div>
<div class="dialog-box">6</div>
<div class="dialog-box">5</div>
<div class="dialog-box">4</div>
<div class="dialog-box">3</div>
<div class="dialog-box">2</div>
<div class="dialog-box">1</div>
</div>
.dialog-container {
border: 4px solid rgba(255, 255, 255, .4);
border-radius: 5px;
width: 300px;
height: 340px;
position: relative;
top: 50px;
margin: 0 auto;
z-index: 5;
display: flex-box;
flex-direction: column;
justify-content: flex-end;
overflow-y: auto;
background-color: teal;
.dialog-box {
width: 90%;
background: black;
margin-bottom: 20px;
border-radius: 8px;
border: 5px solid red;
color: green;
text-align: center;
margin-left: 5px;
padding: 5px;
display: inline-block;
p {}
}
}