可以嵌套flexbox吗?我在水平flexbox中嵌套了一个水平flexbox,在垂直flexbox中嵌套了一个垂直flexbox.只有横向水平在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>
Run Code Online (Sandbox Code Playgroud)
和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;
}
Run Code Online (Sandbox Code Playgroud)
#A在左边,#B在右边.#A和#A2-容器是垂直柔性盒,#B和#B2容器是水平柔性盒.我为不同的div设置颜色,并在每个级别缩小它们(垂直宽度和垂直高度),以便更容易看到正在发生的事情.它在左边看起来很好(在chrome!中),但是在右边,#B2a应该垂直填充#B2(橙色的一个).
我意识到在这个例子中使用一个flexbox更容易在3的中间行/列中使用flex,但我动态地将内容加载到#A2的等效物中,它恰好也是一个弹性箱.
Flexbox可以嵌套,但你必须摆脱你的定位.无论如何,你大多不再需要它了.
从我的经验来看,现在仍然存在的问题是z-stacking flexboxes.并且将主轴上的flexbox项目彼此不同地定位也是不容易的(例如,如果我有一行,我想在左边对齐一个子项目而在右边对齐另一个子项目,我将不得不玩有利润等等可能会变得很痛苦)
此外,根据不同的浏览器,结果可能非常不一致.
无论如何,我鼓励你使用它:http://the-echoplex.net/flexyboxes/ 它有很大帮助.
| 归档时间: |
|
| 查看次数: |
7562 次 |
| 最近记录: |