flex布局如何最后一行左对齐并且间距相同

flex布局 设置justify-content: space-between后最后一行会如下这样:
在这里插入图片描述
在这里插入图片描述

解决:可以在父元素添加after伪类,并在子元素里添加动态类名,proList.content.length是子元素总数,判断最后一行余几个,以下是一行四个为例:

在这里插入图片描述

 :class="(proList.content.length%4)==3?'three-product':''||(proList.content.length%4)==2?'two-product':''||(proList.content.length%4)==0?'zero-product':''"
 .hydrated{
     display:flex;
     justify-content: space-between;
     flex-wrap: wrap;
     &::after{
       content: "";
       flex: auto;
     }
    .three-product{
     &:nth-last-of-type(1),&:nth-last-of-type(2){
        margin-left: 24px;
      }
    }
    .two-product{
      &:nth-last-of-type(1){
        margin-left: 24px;
      }
    }
   .zero-product{
      &:nth-last-of-type(1),&:nth-last-of-type(2),&:nth-last-of-type(3){
      margin-left: 24px;
        }
      }
     .tb-cell{
       width: 23%;
       height:270px;
       margin-bottom: 10px;
       background:rgba(255,255,255,1);
       box-shadow:0px 0px 10px 1px rgba(239,246,252,1);}

最后得到以下的效果
在这里插入图片描述
在这里插入图片描述

  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值