I have a ul
with 5 li
children. Here are the relevant styles:
ul {
display: flex;
flex-flow: row wrap;
justify-content: space-around;
}
This looks great when the viewport is wide enough to fit all 5 items and when it's narrow enough for only 1, 2, or 3 items per row.
The problem is when it's not quite wide enough for all 5, but not narrow enough to break after the third item. As a result, the first 4 items are on the same row, with the fifth item on its own line.
What I'd like is for the flexbox to keep the rows as balanced as possible. So for example, the row lengths should be 3 and 2 instead of 4 and 1, even though a fourth item could technically fit on the top row. Generally, if I had 6 items, instead of breaking 5/1 or 4/2 it would break at 3/3 to keep the rows as balanced as possible.
I've been referencing https://css-tricks.com/snippets/css/a-guide-to-flexbox/ but the grow/basis/shrink styles don't seem to apply here.
Is this only possible with granular media queries or is there a flex-specific style that would help?