<分区>
<分区>
我正在研究一种方法
我有一个主 div 和 2 个其他 div。
.main {
display: flex;
justify-content: space-between;
}
<div class="main">
<div>Goes in the Middle</div>
<div>Goes on the right</div>
</div>
我需要的是间隔 2 个 div 的空间,就好像它有 3 个 div,但只有 2 个。
在没有 3 个 div 的情况下,如何使用 flex 做到这一点?
最佳答案
只需将 div 的宽度设置为 33.33333%
:
.main {
display: flex;
justify-content: space-between;
}
.main>div {
width: 33.3333%;
/* below for test only */
border: 1px solid red;
box-sizing: border-box;
}
/* to push first div into middle - if you want it on left, remove this */
.main>div:first-child {
margin-left:auto;
}
<div class="main">
<div>Goes in the Middle</div>
<div>Goes on the right</div>
</div>
关于css - Flexbox 2 列但间隔为 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51656033/