How can I allow flex-items to grow while keeping the same size?

后端 未结 3 1254
再見小時候
再見小時候 2020-12-19 10:35

Flexbox is one of the coolest tools a web designer could wish for. Unfortunately, sometimes it\'s not immediately obvious what I\'m supposed to do. Take, for example, this p

3条回答
  •  长情又很酷
    2020-12-19 10:38

    This is something that cannot be expressed via CSS Flexbox right now. Someone asked basically this exact question on the CSS Working Group Mailing List a few days ago, and the response was: "At the moment, no, this is not possible. This is a high-priority item for Flexbox 2, though.

    You may be able to hack up something like you want using max-width, though -- that'll prevent flex items (particularly those on the last line) from growing indefinitely. Here's a forked version of your plunk with a nonzero flex-grow, and with max-width: 10em.

    (I chose 10em arbitrarily; you could also use e.g. max-width: calc(100%/5), if you want to make sure each flex item takes up no more than 1/5 of the line, for example.)

提交回复
热议问题