Flex-box: Align last row to grid

后端 未结 29 2490
不知归路
不知归路 2020-11-22 02:54

I have a simple flex-box layout with a container like:

.grid {
  display: flex;
  flex-flow: row wrap;
  justify-content: space-between;
}

29条回答
  •  终归单人心
    2020-11-22 03:18

    You can't. Flexbox is not a grid system. It does not have the language constructs to do what you're asking for, at least not if you're using justify-content: space-between. The closest you can get with Flexbox is to use the column orientation, which requires setting an explicit height:

    http://cssdeck.com/labs/pvsn6t4z (note: prefixes not included)

    ul {
      display: flex;
      flex-flow: column wrap;
      align-content: space-between;
      height: 4em;
    }
    

    However, it would be simpler to just use columns, which has better support and doesn't require setting a specific height:

    http://cssdeck.com/labs/dwq3x6vr (note: prefixes not included)

    ul {
      columns: 15em;
    }
    

提交回复
热议问题