flex布局6个盒子,一行四个平分首行,二行2个靠左,想显示这种情况。第二行设置两个隐藏空盒子来达到8个,然后设置flex-grow: 1即可。

第二行有两个不可见空盒子
代码如下:
<template>
<view class="iconBox">
<view class="iconItem" v-for="(item,index) in iconArr" :key="index">
<image :src="item.ImageUrl" mode="" class="iconImage"></image>
<text class="iconText">{{item.name}}</text>
</view>
<view class="empty"></view>
<view class="empty"></view>
</view>
</template>
样式如下:
<style lang="scss">
.iconBox {
width: auto;
height: 400rpx;
background-color: #fff;
border-radius: 16rpx;
margin: 0 20rpx;
padding: 16rpx;
display: flex;
flex-wrap: wrap;
box-sizing: border-box;
justify-content: flex-start;
// justify-content: center
// align-content: space-between
}
.iconItem {
font-size: 28rpx;
width: 23%;
margin-bottom: 20rpx;
margin-left: 7rpx;
margin-right: 7rpx;
border-radius: 16rpx;
background-color: #f5f7f9;
display: flex;
flex-direction: column;
align-items: center;
justify-items: center;
justify-content: center;
flex-grow: 1;
}
.empty {
visibility: hidden;
width: 23%;
margin-bottom: 20rpx;
margin-left: 7rpx;
margin-right: 7rpx;
border-radius: 16rpx;
background-color: #f5f7f9;
display: flex;
flex-direction: column;
align-items: center;
justify-items: center;
justify-content: center;
flex-grow: 1;
}
.iconText {
text-align: center;
}
.iconImage {
width: 100rpx;
height: 100rpx;
// border: 1rpx solid #666;
}
</style>
本文暂时没有评论,来添加一个吧(●'◡'●)