补位添加节点法,这种方案适用于多种排列方式。

warning 原图

success 实现效果

1
2
3
4
<div class="tem-flex">
<div class="tem-list" v-for="item in len">列表</div>
<div class="list" v-for="item in (row-len%row)" v-if="len%row > 0"></div>
</div>
1
2
3
4
5
6
data(){
return {
len : 14,
row: 4
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
.tem-flex{
display: flex;
flex-wrap: wrap;
justify-content:space-between;
justify-items: center;
text-align: justify;
}
.list{
content: '';
width: 20%;
border:1px solid transparent;
padding: 5px;
overflow: hidden;
}
.tem-list{
width:20%;
border:1px solid #ff6600;
margin-bottom: 10px;
padding: 10px 5px;
display: flex;
justify-content: center;
}

info 这里的 row 即是每列元素的个数,4列,5列。。。更改这个值即可