【发布时间】:2015-11-04 06:39:24
【问题描述】:
我想要一列任意数量的 div,每个 div 的宽度为父 div 的 100%,高度为 100%,所以一个最初是可见的,而其他的则向下溢出父级。我已将 div 设置为具有 flex: 0 0 100%;,在具有 display: flex 和 flex-direction: column 的父 div 内实现此目的。
父 div 本身的高度未知,因此它也是 display: flex 和 flex-direction: column 的子级,设置为 flex: 1 0 0 以占用其容器中的剩余空间。
在 Firefox 中,输出如我所愿:
但是,不是在 Chrome 中:
如何在没有 Javascript 的情况下在 Chrome 中实现 Firefox 风格?
您可以在 http://plnkr.co/edit/WnAcmwAPnFaAhqqtwhLL?p=preview 上看到这一点,以及 flex-direction: row 的相应版本,它在 Firefox 和 Chrome 中都可以正常工作。
完整的 CSS 供参考
.wrapper {
display: flex;
flex-direction: column;
height: 150px;
width: 200px;
border: 4px solid green;
margin-bottom: 20px;
}
.column-parent {
flex: 1 0 0;
display: flex;
flex-direction: column;
border: 2px solid blue;
}
.column-child {
flex: 0 0 100%;
border: 2px solid red;
}
和 HTML
<div class="wrapper">
<p>Some content of unknown size</p>
<div class="column-parent">
<div class="column-child">
Should be inside green
</div>
<div class="column-child">
Should be outside green
</div>
</div>
</div>
【问题讨论】:
-
请注意,在 Firefox 中 - 如果您添加额外的列子元素 - 它们会崩溃(就像在 Chrome 中一样)Plunker
-
我在我的回答中添加了另一个解决方案,不太老套
标签: html css google-chrome firefox flexbox