If I have html like this:
<div id="a">
<div>a</div>
<div>b</div>
<div>c</div>
<div>d</div>
<div>e</div>
<div>f</div>
<div>g</div>
<div>h</div>
<div>i</div>
</div>
I know I can make the items nicely spaced out as in the picture with the red boxes using a flex
box, justify-content: space-around
, and flex-wrap:wrap
. But I'm wondering, is it possible with just css to make the items space themselves out such that the items spread out vertically and horizontally, like in the green image where it would attempt to put the same number of items in each line/row (as long as they're all the same dimensions)?
I'm interested in the case where you don't know ahead of time how many items will be inside the main div #a
and you don't know their widths either.
Here's a js-fiddle of the red-boxes version: https://jsfiddle.net/p0Lahgbj/