我有一个带有包装物品的弹箱:
.flex-container {
padding: 0;
margin: 0;
list-style: none;
border: 1px solid silver;
-ms-box-orient: horizontal;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -moz-flex;
display: -webkit-flex;
display: flex;
width: 520px;
height: 520px;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
}
.flex-item {
background: gold;
padding: 5px;
width: 100px;
height: 100px;
margin: 10px;
line-height: 100px;
color: white;
font-weight: bold;
font-size: 2em;
text-align: center;
}

<ul class="flex-container wrap">
<li class="flex-item">1</li>
<li class="flex-item">2</li>
<li class="flex-item">3</li>
<li class="flex-item">4</li>
<li class="flex-item">5</li>
<li class="flex-item">6</li>
<li class="flex-item">7</li>
<li class="flex-item">8</li>
</ul>
&#13;
https://jsfiddle.net/0v54s2Lz/1/
我希望5,6,7和8在1,2,3和4之下。但是存在差距。据推测,Flexbox试图平衡&#34;行&#34;高度。
答案 0 :(得分:2)
你必须添加
align-content: flex-start;
到.flex-container。
.flex-container {
padding: 0;
margin: 0;
list-style: none;
border: 1px solid silver;
-ms-box-orient: horizontal;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -moz-flex;
display: -webkit-flex;
display: flex;
width: 520px;
height: 520px;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
align-content: flex-start;
}
.flex-item {
background: gold;
padding: 5px;
width: 100px;
height: 100px;
margin: 10px;
line-height: 100px;
color: white;
font-weight: bold;
font-size: 2em;
text-align: center;
}
<ul class="flex-container wrap">
<li class="flex-item">1</li>
<li class="flex-item">2</li>
<li class="flex-item">3</li>
<li class="flex-item">4</li>
<li class="flex-item">5</li>
<li class="flex-item">6</li>
<li class="flex-item">7</li>
<li class="flex-item">8</li>
</ul>
答案 1 :(得分:-1)
从height: 520px;
移除.flex-container
,此处已更新fiddle