【发布时间】:2016-12-23 19:38:04
【问题描述】:
假设我们有这个标记:
<div id="outer">
<div id="middle">
<div id="inner">
</div>
</div>
</div>
还有这个css:
#outer {
display: flex;
flex-direction: column;
background-color: white;
height: 300px;
}
#middle {
flex-grow: 1;
background-color: beige;
}
#inner {
background-color: black;
height: 100%;
}
我希望内部 div 跨越整个 300 像素,因为它应该与中间的 flex 项一样高,而中间的 flex 项又会填充其父项。
这是我在 IE、Edge 和 Firefox 上看到的行为。
在 Chrome 上,中间 div 仍然填充 300 像素,但内部 div 与没有任何高度属性时一样高。
看到这个小提琴:https://jsfiddle.net/mhjussna/
这是 Chrome 中的错误,对吧?
【问题讨论】:
-
height:100%使用 flex 会出错。而是在#outer元素上使用align-items: stretch。 -
align-item用于水平对齐,当flex-direction为column - so it has no bearing on the question. Also note I don't useheight: 100%` 时,在任何直接参与 flex 布局的元素上。
标签: css google-chrome flexbox