【发布时间】:2018-04-19 03:22:57
【问题描述】:
我在 flex 中有一个非常基本的网格设置,但我最近遇到了一个疏忽。
我的列具有右边距:3em 和 flex-basis:calc(33% - 3em)。
我的问题是,这些中的第 4 和第 5 不会排成一行,直到有 3 个完整的“行”。
关于为什么会发生这种情况的任何见解?我想我可能像往常一样把事情复杂化了。
section {
width: 1170px;
margin: 0 auto;
padding: 4em;
background-color: lightgray;
}
.flex {
display: flex;
}
.wrap {
flex-wrap: wrap;
}
.column {
flex: 1;
flex-direction: column;
margin-right: 3em;
}
.column:last-child {
margin-right: 0;
}
.three {
max-width: 33%;
flex-basis: calc(33% - 3em);
}
.three:nth-child(3n) {
margin-right: 0;
}
.debug {
margin-bottom: 3em;
background-color: #ebf5fb;
height: 3em;
border: 1px dashed red;
text-align: center;
}
<section>
<div class="flex wrap">
<div class="column three debug">3 Columns</div>
<div class="column three debug">3 Columns</div>
<div class="column three debug">3 Columns</div>
<div class="column three debug">3 Columns</div>
<div class="column three debug">3 Columns</div>
</div>
</section>
【问题讨论】: