flexboxes可以嵌套吗?我在水平 flexbox 中嵌套了一个水平 flexbox,在垂直 flexbox 中嵌套了一个垂直 flexbox。只有 horizontal in horizontal 在 chrome 中有效,在 firefox 中均无效!
我在这里创建了一个 jsfiddle:http://jsfiddle.net/NpkTL/1/
但这是 html:
<div id="A">
<div id="A1">A1</div>
<div id="A2">
<div id="A2-container">
<div id="A2a">A2a</div>
<div id="A2b">A2b</div>
</div>
</div>
</div>
<div id="B">
<div id="B1">B1</div>
<div id="B2">
<div id="B2-container">
<div id="B2a">B2a</div>
<div id="B2b">B2b</div>
</div>
</div>
</div>
和 CSS:
* {
margin: 0;
padding: 0;
font-family: Arial;
}
#A {
position: absolute;
top: 0px;
left: 0px;
background: black;
width: 50%;
height: 100%;
display: -moz-box;
display: -webkit-box;
display: box;
-moz-box-orient: horizontal;
-webkit-box-orient: horizontal;
box-orient: horizontal;
}
#A1 {
background: brown;
width: 100px;
height: 80%;
}
#A2 {
background: orange;
height: 80%;
-moz-box-flex: 1;
-webkit-box-flex: 1;
box-flex: 1;
}
#A2-container {
display: -moz-box;
display: -webkit-box;
display: box;
-moz-box-orient: horizontal;
-webkit-box-orient: horizontal;
box-orient: horizontal;
width: 100%;
height: 100%;
}
#A2a {
background: red;
height: 80%;
-moz-box-flex: 1;
-webkit-box-flex: 1;
box-flex: 1;
}
#A2b {
background: blue;
width: 100px;
height: 80%;
}
#B {
position: absolute;
top: 0px;
right: 0px;
background: gray;
width: 50%;
height: 100%;
display: -moz-box;
display: -webkit-box;
display: box;
-moz-box-orient: vertical;
-webkit-box-orient: vertical;
box-orient: vertical;
}
#B1 {
background: brown;
width: 80%;
height: 100px;
}
#B2 {
background: orange;
width: 80%;
-moz-box-flex: 1;
-webkit-box-flex: 1;
box-flex: 1;
}
#B2-container {
display: -moz-box;
display: -webkit-box;
display: box;
-moz-box-orient: vertical;
-webkit-box-orient: vertical;
box-orient: vertical;
width: 100%;
height: 100%;
}
#B2a {
background: red;
width: 80%;
-moz-box-flex: 1;
-webkit-box-flex: 1;
box-flex: 1;
}
#B2b {
background: blue;
width: 80%;
height: 100px;
}
#A在左边,#B在右边。 #A 和#A2-container 是垂直 flex 盒,#B 和#B2-container 是水平 flex 盒。我为不同的 div 设置颜色,并在每个级别(垂直宽度和垂直高度)缩小它们,以便更容易看到发生了什么。它在左侧看起来不错(在 chrome 中!),但在右侧,#B2a 应该垂直填充 #B2(橙色的)。
我意识到在这个例子中使用一个 flexbox 在中间行/列 3 中会更容易,但我动态地将内容加载到 #A2 的等价物中,它恰好也是一个 flexbox .
最佳答案
Flexboxes 可以嵌套但是你必须摆脱你的定位。反正你基本上不再需要它了。
根据我的经验,现在仍然存在的问题是 z-stacking flexboxes。 并且在主轴上将 flexbox 元素彼此不同地定位也不是直接的(例如,如果我有一行并且我想在左侧对齐一个子元素而在右侧对齐另一个子元素,我将不得不玩有边缘等可能会变得痛苦)
此外,根据不同的浏览器,结果可能会非常不一致。
无论如何,我鼓励你使用这个:http://the-echoplex.net/flexyboxes/ 这很有帮助。
关于css - 嵌套的 CSS3 flexboxes 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10553981/