flex-flow:列包装,在弹性框中导致父容器溢出

时间:2016-03-10 14:55:16

标签: html css css3 flexbox

我有这种情况:

https://jsfiddle.net/b6zcdgf7/

.container{
  display:flex;
  height:3em;
  border:solid thin blue;
}
.section{
  border:solid thin gray;
  display:flex;
}
.section.horiz{
  
}

.section.vert{
  flex-direction:column;
  flex-wrap: wrap;
}

.box{
  border:solid thin red;
  width:1em;
  height:1em;
}
<div class="container">
  <div class="section horiz">
    <div class="box"></div>
    <div class="box"></div>
  </div>
  <div class="section horiz">
    <div class="box"></div>
    <div class="box"></div>
  </div>
  <div class="section horiz">
    <div class="box"></div>
  </div>
  <div class="section vert">
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
  </div>
</div>

使用.section.vert时,.box元素会溢出该部分。

我能做些什么来防止必须在.section.vert元素上设置宽度?

1 个答案:

答案 0 :(得分:1)

flex-wrap更改为nowrap

.section.vert{
  flex-direction:column;
  flex-wrap: nowrap;
  outline: 3px dashed green;

}

Fiddle

<强>段

.container{
  display:flex;
  height:3em;
  border:solid thin blue;
}
.section{
  border:solid thin gray;
  display:flex;
}
.section.horiz{
  
}

.section.vert{
  flex-direction:column;
  flex-wrap: nowrap;
  outline: 3px dashed green;

}

.box{
  border:solid thin red;
  width:1em;
  height:1em;
}
<div class="container">
  <div class="section horiz">
    <div class="box"></div>
    <div class="box"></div>
  </div>
  <div class="section horiz">
    <div class="box"></div>
    <div class="box"></div>
  </div>
  <div class="section horiz">
    <div class="box"></div>
  </div>
  <div class="section vert">
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
  </div>
</div>