为什么嵌套的Flexbox无法在Chrome中使用?

时间:2018-08-09 14:00:20

标签: css css3 flexbox

我有带嵌套flexbox的代码:https://jsfiddle.net/tomrhodes/8pf1q706/,我希望“内容2”总是填充剩余的空间。它可以在Firefox上运行,但不能在Google Chrome上运行,为什么不起作用?

非常重要的是,不要同时使用一个div元素作为项目和flexbox的父项,因此-我已经清楚地将这些角色分开了。

html,
body {
  height: 100%;
  margin: 0;
  border: solid magenta;
}

.row2 {
  background: #f8f9fa;
  margin-top: 20px;
  flex: 0 1 auto;
  -webkit-flex: 0 1 auto;
}

.container {
  display: flex;
  display: -webkit-flex;
  flex-flow: column;
  -webkit-flex-flow: column;
  height: 100%;
  border: solid blue;
}

.box {
  display: flex;
  flex-flow: column;
  height: 100%;
  border: solid blue;
}

.outsidebox {
  display: flex;
  flex-flow: column;
  height: 100%;
  border: solid purple;
}

.headerstyle {
  flex: 0 1 auto;
  border: solid green;
}

.contentstyle {
  flex: 1 1 auto;
  border: solid green;
}

.footerstyle {
  flex: 0 1 40px;
  border: solid green;
}

.wrapper {
  flex: 1 1 auto;
  border: solid yellow;
}
<div class="outsidebox">
  <div class="box">
    <div class="headerstyle">header</div>
    <div class="contentstyle">
      <div class="outsidebox">
        <div class="headerstyle">header 2</div>
        <div class="contentstyle">content 2</div>
        <div class="footerstyle">footer 2</div>
      </div>
    </div>
    <div class="footerstyle">footer</div>
  </div>
</div>

1 个答案:

答案 0 :(得分:1)

我想这就是您要追求的-我使内容样式的弯曲方向与列方向一致,并且flex增长,因此它填充了父容器:

* {box-sizing:border-box;}
html,
body {
  height: 100%;
  margin: 0;
  border: solid magenta;
}

.row2 {
  background: #f8f9fa;
  margin-top: 20px;
  flex: 0 1 auto;
  -webkit-flex: 0 1 auto;
}

.container {
  display: flex;
  display: -webkit-flex;
  flex-flow: column;
  -webkit-flex-flow: column;
  height: 100%;
  border: solid blue;
}

.box {
  display: flex;
  flex-flow: column;
  height: 100%;
  border: solid blue;
}

.outsidebox {
  flex-grow:1;
  display: flex;
  flex-flow: column;  
  height: 100%;
  border: solid purple;
}

.headerstyle {
  flex: 0 1 auto;
  border: solid green;
}

.contentstyle {
  flex-grow:1;
  display:flex;
  flex-direction:column;   /* make this flex and column */
  border: solid green;
  width:100%;
}

.footerstyle {
  flex: 0 1 40px;
  border: solid green;
}

.wrapper {
  flex: 1 1 auto;
  border: solid yellow;
}
<div class="outsidebox">
  <div class="box">
    <div class="headerstyle">header</div>
    <div class="contentstyle">
      <div class="outsidebox">
        <div class="headerstyle">header 2</div>
        <div class="contentstyle">content 2</div>
        <div class="footerstyle">footer 2</div>
      </div>
    </div>
    <div class="footerstyle">footer</div>
  </div>
</div>

或简化为:

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  border: solid magenta;
}

.outsidebox {
  display: flex;
  flex-flow: column;
  flex-grow: 1;
  height: 100%;
  border: solid purple;
}

.headerstyle {
  flex: 0 1 auto;
  border: solid green;
}

.contentstyle {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  border: solid green;
  width: 100%;
}

.footerstyle {
  flex: 0 1 40px;
  border: solid green;
}
<div class="outsidebox">
  <div class="headerstyle">header</div>
  <div class="contentstyle">
    <div class="outsidebox">
      <div class="headerstyle">header 2</div>
      <div class="contentstyle">content 2</div>
      <div class="footerstyle">footer 2</div>
    </div>
  </div>
  <div class="footerstyle">footer</div>
</div>