I have a container with a variable number of elements in it. Elements should be justified, but with a fixed space between (e.g. 20px ). This means that the width of each element must adapt.
For instance:
HTML
<div class="container"> <div> <img src="..."> </div> <div> <img src="..."> </div> <div> <img src="..."> </div> </div>
CSS
div.container { text-align: justify; } div.container div { display: inline-block; margin-right: 20px; } div.container div img { width: 100%; }
At the end, it should look like this (in this figure two examples are shown: 2 elements and 3 elements, the width is dynamic, but the fix space [20px]):

It should work with a different number of children .
Is there a professional way to do this using CSS?
EDIT : I have to mention that this fixed space is a% value!
source share