I've got flex container with multiple items in it. It's very simple - 100% width container with text element inside. Text elements can be various width and need to all fit within the 100% width. If the width is not enough, the individual elements may wrap as required. This works quite well.
Now, when there is enough width for all elements to fit without wrapping, there is equal white space between them. However when the elements shrink in width and text wraps, they don't seem to be correctly spaced any more. It seems that the flex basis does not calculate correctly and as a result, those elements that wrap end up having a much larger white space on the right (it's an ltr container).
Here's the jsfiddle and the relevant code:
HTML:
<ul>
<li>Longer item</li>
<li>Short</li>
<li>Even longer item</li>
<li>Another long item</li>
<li>And another one</li>
<li>Item6</li>
<li>Item 7</li>
<li>Average item</li>
<li>I need a few</li>
<li>This should be enough</li>
</ul>
CSS:
ul {
width: 100%;
display: flex;
justify-content: space-around;
padding: 0;
}
li {
flex: 1 1 auto;
list-style: none;
padding: 5px;
}
All equal spacing when no wrap:
How can I get the spacing between items to always be equal regardless of the wrapping (or not) of individual items)?