前提条件:content="width=750"
css
<meta name="viewport" content="width=750,user-scalable=no,target-densitydpi=device-dpi,viewport-fit=cover">
复制代码
效果图以下:html
高宽:bash
间距:布局
圆角10:spa
概括法scala
你们在中学的时候都学过数学的概括法,就是一个命题先求出n=1的时候成立,而后假设n=k成立,证实n=k+1也成立,从而证得命题在n=k【k=任意实数】的时候都成立。3d
代码code
<div class="grid-img-box">
<van-image class='grid-img' v-for="value in data.photo" :key="value" fit="cover" :src="value" />
</div>
复制代码
.grid-img{
/**
宽高
1. 3n+1且是倒数第2张时
2. 3n+1且是最后一张时
以上两种状况图片的宽高均应为320;
剩余两种状况是:
3. 只有一张时宽高320;
4. 其他的状况和索引宽高都为220;
*/
display: inline-block;
width: 220px;
height: 220px;
&:only-child{
width: 320px;
height: 320px;
}
&:nth-child(3n+1):nth-last-child(2),
&:nth-child(3n+2):last-child{
width: 332px;
height: 332px;
}
/**
间距/布局
*/
&:nth-child(3n+2){
margin: 0 6px;
}
&:nth-child(n+4){
margin-top: 6px;
}
&:first-child{
border-top-left-radius: 10px;
}
&:last-child{
margin-right: 0;
border-bottom-right-radius: 10px;
}
/**
圆角
*/
//左下圆角:最后一行第一个
&:nth-child(3n+1){
&:last-child,
&:nth-last-child(2),
&:nth-last-child(3){
border-bottom-left-radius: 10px;
}
}
//处理四个布局
//增大第二个margin讲第三个挤到下一行
&:nth-child(2):nth-last-child(3){
margin-right: 220px;
}
//重置第二个圆角
&:nth-child(2):nth-last-child(3){
border-top-right-radius: 10px;
}
//重置第三个的margin和radius
&:nth-child(3):nth-last-child(2){
margin-top: 6px;
margin-right: 6px;
border-radius: 0 0 0 10px;
}
//重置第4个的圆角
&:nth-child(4):last-child{
border-radius: 0 0 10px 0;
}
}
复制代码