在实际开发过程中,经常会使用到流式布局,需要有间隔同时排列整齐,我这里用到: justify-content: space-between;布局 但是这样有问题,就是 最后一行不能左对齐,解决办法如下:
.parent{
display: flex;
justify-content: space-between;
flex-wrap: wrap;
&::after {
content: '';
flex: auto;
}
}
但是其实上面的思路还是有问题,flex: auto;以后,最后一行的间隙会被这个auto占完,导致最后一行的排列都黏在一起(使最后一行的边距失效) 由于我这里刚刚好是3个(只有这一种场景可以用),所以将上面的代码改了一下,正好解决问题(核心就是把最后一个通过伪元素占了),如下:
user-list-wrapper{
display: flex;
flex-wrap: wrap;
justify-content: space-between;
margin-top: 2.8125rem;
&:after {
content: '';
flex: 0 1 24.0625rem;
}
.user-box{
width: 24.0625rem;
height: 19.9375rem;
margin-bottom: 2.84375rem;
cursor: pointer;
}
}
