多个元素,先列后行排列

多个元素,先列后行排列

问题描述及解决方案

由于各个元素长短不一,如果使用flex或者grid布局,按照先行后列排列,就会出现下面这种空白(椭圆处)。

问题描述

在这里插入图片描述

解决方案

使用column布局,采用先列后行排列,可以避免出现大量的空白行
在这里插入图片描述

demo

<template>
  <div class="test">
    <div class="list">
      <aside class="list_i" v-for="(item, idx) in children" :key="idx">{{ idx + 1 }} {{ item.title }}</aside>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      children: [
        { title: "Consultation" },
        { title: "Planning and Designing" },
        { title: "Clean Room & Special Ward Projects and Auxiliary Equipment" },
        { title: "Hospital Logistics Transmission System and Auxiliary Equipment" },
        { title: "Medical Gas Engineering and Auxiliary Equipment" },
        { title: "Hospital Water System and Supporting Equipment System Solutions" },
        { title: "Hospital HVAC Electrical and Weak Power System Construction Solutions" },
        { title: "Laboratory Projects and Equipment Exhibition Area" },
        { title: "Indoor Environment Decoration, Interior Design and Material Application Hospital Soft Furnishings and Furniture Equipment" },
        { title: "Innovative Technical Solutions for Hospital Windows, Doors, Curtain Walls and Accessories" },
        { title: "Green Hospital Building/Hospital Energy Saving Reconstruction and Operation Services" },
        { title: "Smart Hospital System Solutions" },
      ],
    };
  },
  mounted() {},
  methods: {},
};
</script>

<style lang="scss" scoped>
.test {
  padding: 40px;
  // column
  .list {
    border: 1px solid #f00;
    width: 600px;

    column-count: 2; /* 创建两列 */
    column-gap: 0; /* 设置列与列之间的间隙 */

    &_i {
      border: 1px solid #f00;
      padding: 10px;
      line-height: 2em;
      break-inside: avoid;
    }
  }
  //   grid
  //   .list {
  //     border: 1px solid #f00;
  //     width: 600px;
  //     display: grid;
  //     grid-template-columns: repeat(2, 1fr);

  //     &_i {
  //       border: 1px solid #f00;
  //       padding: 10px;
  //       line-height: 2em;
  //       break-inside: avoid;
  //     }
  //   }
}
</style>

如果你有更好的解决方案,欢迎指正,希望您不吝赐教

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值