I am facing a situation where I have a container with multiple elements inside it. These elements need to be justified and spaced out by a fixed amount (e.g. 20px
). This means that the width of each element should adjust accordingly.
For instance, consider the following:
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%;
}
The end result should resemble this image (displaying examples with 2 and 3 elements; dynamic width but fixed space [20px]):
This layout should work seamlessly with a varying number of child elements.
Is there an elegant solution using CSS in this scenario?
EDIT: It's worth noting that the fixed space mentioned is a %-value!