Is it possible to display flexbox items in two rows instead of one?

后端 未结 1 1717
悲&欢浪女
悲&欢浪女 2021-01-21 21:23

What I\'m trying to accomplish here is, I want to use two rows to display uncertain amount of items. I will use vertical scroll to show overflowed items. If I use below css then

相关标签:
1条回答
  • 2021-01-21 21:54

    You can do this using CSS grid:

    .items-list {
      display: grid;
      grid-template-rows: 50px 50px; /* 2 rows of 50px */
      grid-auto-flow: column;  /* a column flow */
      grid-auto-columns:100px; /* each column will 100px of width */
      grid-gap: 5px;
      overflow: auto;
    }
    .item {
      border:2px solid red;
    }
    <div class="items-list">
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
      <div class="item"></div>
    </div>

    Related question to get another kind of layout: Can I use css-grid to display an unknown number of items, in left-to-right reading order, over two rows?

    0 讨论(0)
提交回复
热议问题