我有一个行布局,在根容器的第二个flex项中有一个嵌套的flex容器.我希望嵌套的flex容器是其父级的已用高度的100%.
<div class="steps root"><!--root container-->
<div class="step one">
I am very tall. Others should be as high as I am!
</div>
<div class="step two-and-three">
<div class="steps"><!--nested container-->
<div class="step two">
nested child 1. should have 100% vertical height
</div>
<div class="step three">
nested child 2. should have 100% vertical height
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这是演示这个问题的小提琴:http://jsfiddle.net/2ZDuE/316/
如果我为嵌套的flex容器设置了显式高度,那么一切正常.
如何告诉嵌套容器自动填充其容器的垂直空间?
添加display:flex
到.step.two-and-three
和删除padding-bottom
.steps.root {
width: 700px;
}
.steps.root>.step.one {
height: 300px;
/*simulate big content in left column*/
}
.steps {
display: flex;
}
.step.one {
flex: 1 1 33%;
background-color: rgba(0, 0, 0, 0.1);
}
.step.two-and-three {
flex: 2 1 66%;
background-color: grey;
display: flex; /* added */
}
.step.two {
flex: 1 1 50%;
background-color: green;
}
.step.three {
flex: 1 1 50%;
background-color: lime;
}
.step.two-and-three>.steps {
background-color: olive;
padding-bottom: 10px;
}
Run Code Online (Sandbox Code Playgroud)
<div class="steps root">
<!--root container-->
<div class="step one">I am very tall. Others should be as high as I am!</div>
<div class="step two-and-three">
<div class="steps">
<!--nested container-->
<div class="step two">nested child 1. should have 100% vertical height</div>
<div class="step three">nested child 2. should have 100% vertical height</div>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)