我正在尝试将元素放置在带有 flex-wrap 的 Flexbox 中,中间有间隙
理想的显示方式应该是:
最终结果应该是这样的:
.container {
max-width: 200px;
width: 200px;
display: flex;
flex-wrap: wrap;
gap: 12px;
padding: 0 12px 0 12px;
}
.item1 {
width:33%;
height: 200px;
background-color: red;
}
.item2 {
width:66%;
height: 200px;
background-color: green;
}
.item3 {
width: 100%;
height: 200px;
background-color: blue;
}Run Code Online (Sandbox Code Playgroud)
<div class="container">
<div class="item3"></div>
<div class="item1"></div>
<div class="item2"></div>
</div>Run Code Online (Sandbox Code Playgroud)
小智 0
我添加了一个 flex-direction: row,删除了填充并向宽度添加了一个计算函数,并将 66% 提高到 67% 以创建 100% 总计。
.container {
max-width: 200px;
width: 200px;
display: flex;
flex-direction: row;
flex-wrap: wrap;
gap: 12px;
}
.item1 {
width: calc(33% - 6px);
height: 200px;
background-color: red;
}
.item2 {
width:calc(67% - 6px);
height: 200px;
background-color: green;
}
.item3 {
width: 100%;
height: 200px;
background-color: blue;
}Run Code Online (Sandbox Code Playgroud)
<div class="container">
<div class="item3"></div>
<div class="item1"></div>
<div class="item2"></div>
</div>Run Code Online (Sandbox Code Playgroud)