一行三列循环自适应,是移动端常见的布局

当使用display flex justify-content: space-between;最后一行只有两个时候,会出现分居两端,我们此时需要把最后一行改为向前布局

我的解决方案如下:

<div>
  <p class="item">1</p>
  <p class="item">1</p>
  <p class="item">1</p>
  <p class="item">1</p>
  <p class="item">1</p>
  <p class="item">1</p>
  <p class="item">1</p>
  <p class="item">1</p>
  <p class="item"></p> // 在最后一项添加一个空块
</div>

然后css

 

        .field-item:nth-last-of-type(1):nth-of-type(3n+1) {
          display: none;
        }

  如果有更好的,也欢迎给出

相关文章:

  • 2021-07-09
  • 2022-12-23
  • 2022-12-23
  • 2021-12-16
  • 2022-12-23
  • 2022-12-23
  • 2022-01-16
  • 2022-12-23
猜你喜欢
  • 2021-11-24
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案