CSS嵌套弹性框高度

时间:2014-12-22 16:35:16

标签: css3 flexbox

我在根容器的第二个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>

以下是演示此问题的小提琴:http://jsfiddle.net/2ZDuE/316/

如果我为嵌套的flex容器设置了显式高度,那么一切正常。

如何告诉嵌套容器自动填充其容器的垂直空间?

1 个答案:

答案 0 :(得分:5)

display:flex添加到.step.two-and-three并删除padding-bottom

&#13;
&#13;
.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;
}
&#13;
<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>
&#13;
&#13;
&#13;