我试图每行显示 2 列,但目前似乎无法正确显示。
但我不确定如何使用 flexbox 来处理这个问题
.flex {
display: flex;
flex-direction: row;
flex-basis: 100%;
flex: 1;
}
.box {
padding: 20px;
border: 1px solid black;
width: 100px;
height: 100px;
margin: 10px;
}
.red {
background-color: red;
}
.yellow {
background-color: yellow;
}
.blue {
background-color: blue;
}
.green {
background-color: green;
}
<div class="flex">
<div class="box green">positive 1</div>
<div class="box yellow">positive 2</div>
<div class="box blue">positive 3</div>
<div class="box red">negative 1</div>
</div>
https://jsfiddle.net/1a9qLx5w/
原文由 deathknight256 发布,翻译遵循 CC BY-SA 4.0 许可协议
实现这种布局的最佳方式是使用 Grid CSS:
但是既然你要求的是 flexbox 解决方案,那么你可以这样做: