I would like to display a row of 2-5 figures containing an image and a caption.
The figures must have the same height and the aspect ratio of the images must be maintained.
HTML would look something like this:
<div class="container">
<figure style="--w:100; --h:100;">
<img src="https://placehold.co/100x100/f08/fff" style="--w:100; --h:100;">
<figcaption>caption</figcaption>
</figure>
<figure style="--w:200; --h:40;">
<img src="https://placehold.co/200x40/0f8/fff" style="--w:200; --h:40;">
<figcaption>caption</figcaption>
</figure>
<figure style="--w:150; --h:200;">
<img src="https://placehold.co/150x200/8f0/fff" style="--w:150; --h:200;">
<figcaption>caption</figcaption>
</figure>
<figure style="--w:250; --h:200;">
<img src="https://placehold.co/250x200/f80/fff" style="--w:250; --h:200;">
<figcaption>caption</figcaption>
</figure>
</div>
I’ve found something similar here, but it doesn’t work right with the figure element, unless I use object fit cover on the img tag.
2
Answers
Here is a better approach to perfectly fit all the images inside the figure container.
You can use : max-height and min-height properties to limit the image dimension. Then
object-fit: cover
will maintain the image view.Here’s another approach that I tried
As the second image is a bit wider in dimensions, so its getting stretched out.
Hope this helps..