How to keep wrapped flex-items the same width as the elements on the previous row?

前端 未结 13 1213
一整个雨季
一整个雨季 2020-11-29 01:24

I have a

    that is a flex-box and a bunch of
  • s in it which are the flex-items.

    I am trying to get the

13条回答
  •  孤街浪徒
    2020-11-29 01:43

    Alternative - grid

    its not the answer of what you want, but it nice to use:

    display: grid
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr))
    

    https://codepen.io/omergal/pen/povzJrz

    ul {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    }
    
    li {
      min-width: 40px;
      max-width: 100px;
    }
    
    ul,
    li {
      margin: 0;
      padding: 0;
      list-style: none;
    }
    ul {
      background-color: tomato;
    }
    
    li {
      margin: 0.5em;
      background-color: darkgreen;
    }
    
    img {
      width: 100%;
      opacity: 0.5;
    }
    figure,
    img {
      margin: 0;
      padding: 0;
    }

提交回复
热议问题