Solution
Instead of justify-content: space-around
use justify-content: space-between
.
Explanation
Take a look at the flexbox spec:
8.2. Axis Alignment: the
justify-content
propertyThe
justify-content
property aligns flex items along the main axis
of the current line of the flex container.
There are five values that apply to justify-content
. Here are two of them:
space-around
Flex items are evenly distributed in the line, with half-size spaces
on either end.If the leftover free-space is negative or there is
only a single flex item on the line, this value is identical to
center
.
Emphasis mine. That’s the problem you’re having.
Now check out space-between
:
space-between
Flex items are evenly distributed in the line.
If the leftover free-space is negative or there is only a single flex item on the line, this value is identical to
flex-start
.
So, to left-align your flex item on wrap, use space-between
.
Then, if necessary, you can add some left and right padding to the container to simulate space-around
.
Of course, the next problem you’ll face is when two items wrap, and each item aligns at opposite ends. But that’s another question altogether 🙂