最终实现的效果如下:
1、HTML代码
<div class="volume-wrapper">
<div class="volume-item">
<div class="title">自然月合同量</div>
<div class="volume">54.3772</div>
</div>
<div class="volume-item">
<div class="title">自然月剩余合同量</div>
<div class="volume">54.3772</div>
</div>
<div class="volume-item">
<div class="title">自然月剩余合同日均量</div>
<div class="volume">54.3772</div>
</div>
<div class="volume-item">
<div class="title">结算月合同量</div>
<div class="volume">54.3772</div>
</div>
<div class="volume-item">
<div class="title">结算月剩余合同量</div>
<div class="volume">54.3772</div>
</div>
<div class="volume-item">
<div class="title">结算月剩余合同日均量</div>
<div class="volume">54.3772</div>
</div>
<div class="volume-item">
<div class="title">智能填报规则名称</div>
<div class="volume">54.3772</div>
</div>
</div>
2、CSS样式代码
(1)父元素CSS:
.volume-wrapper {
display: flex; /* flex布局 */
justify-content: flex-start; /* 左对齐 */
flex-wrap: wrap; /* 换行 */
}
(2)子元素CSS:
.volume-item{
margin-right: 20px; /* 每个元素右间距设置为20px */
/* 计算每个元素的宽度:20px是前三个元素的间距(margin-right)和,除以4即为每个元素的宽度 */
width: calc((100% - 20px) / 4);
}
/* 将下标是4的倍数元素的margin-right设置为0,即将每行最后一个元素的margin-right置0 */
.volume-item:nth-of-type(4n+0) {
margin-right: 0;
}