I’ve had difficulty figuring out how to cleanly do precicely what I am asking in the title.
Say for example I have a something like this:
<div class="image-row">
<img src="image1">
<img src="image2">
<img src="image3">
<img src="image4">
<img src="image5">
</div>
I have seen answers to similar questions, but they don’t deal with the issue of spreading mixed width elements across a responsive parent element.
In something like Photoshop, this is called “Distribute horizontal centers”. Here is an example I made in photoshop (500px wide image-row):
here are the same boxes when image-row is stretched to 900px wide:
Note that the gaps between the images are not necessary even, the the spread is even based on the horizontal centers of the objects.
How can I accomplish this basic idea in css?
3
Answers
Try this:
html
css
You may use
text-align:justify
and a pseudo for older browser or use thedisplay:flex
properties for latest browsers.You can use a flex display and set justify-content to space-between. You can do that on your image-row class:
The point is to use this class on the container div.