flex 三列多行布局


查看效果图

 

 

参考其他朋友的实现思路,

添加一行隐藏的元素占位,然后列表元素设置 flex。

<template>
  <div>
    <div class="image">
      <ul>
        <li v-for="(item, index) in list" :key="index">{{item}}</li>
        <li class="bt_classify_name_empty" style="visibility: hidden"></li>
      </ul>
      <button @click="addImage">添加图片</button>
    </div>
  </div>
</template>

<script>
  export default {
  data() {
    return {
      list: [],
      a: 0
    };
  },
  methods: {
    addImage () {
      this.a += 1;
      this.list.unshift(this.a);
    }
  },
}
</script>

<style lang='less' scoped>
.image {
  ul {
    padding: 0;
    margin: 0;
    list-style: none;
    padding: 1rem;
    box-sizing: border-box;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-between;
    li {
      flex: 0 0 30%;
      height: 6rem;
      display: inline-block;
      background: #ededee;
      margin-bottom: 1rem;
      text-align: center;
    }
    .bt_classify_name_empty {
      width: 0px;
      height: 0px;
    }
  }
}
</style>

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM