img {
height: 50px;
}
<div>
<div>
<img src="https://upload.wikimedia.org/wikipedia/commons/a/a6/U%2B25C9.svg"/>
<img src="https://upload.wikimedia.org/wikipedia/commons/a/a6/U%2B25C9.svg"/>
<img src="https://upload.wikimedia.org/wikipedia/commons/a/a6/U%2B25C9.svg"/>
</div>
<div>
<img src="https://upload.wikimedia.org/wikipedia/commons/a/a6/U%2B25C9.svg"/>
<img src="https://upload.wikimedia.org/wikipedia/commons/a/a6/U%2B25C9.svg"/>
<img src="https://upload.wikimedia.org/wikipedia/commons/a/a6/U%2B25C9.svg"/>
</div>
</div>
As you can see I managed to arrange the images in two rows however, this required putting them into two two div
s. Now the items are dynamically generated and their number is not known upfront. Clearly it's not difficult to write JS that will arrange the items correctly into these two divs however, I'm interested if I can avoid this nonetheless?
Namely, I'm interested if I can write CSS that will arrange all items into evenly-sized rows (that is, eg 4 items in one row nad 4 in the other, not 6 in one row and 2 in the other) without the use of the intermediate divs? So that all img
s will be direct children of the outermost div
only and once their number changes (some are added, some are removed) they will rearrange themselves properly without any extra JS code to rearrange them into div
s or to change class or inline style of, say, the n/2
th img
?
EDIT: Just like in my snippet I want the images to occupy only as much horizontal space as necessary and NOT to stretch to the full width of the enclosing container. This is actually required.