I have the following HTML and CSS for an image with caption combination but I’m struggling to make it responsive. The code is used for a dozen or more images all of different sizes. I know well enough the principle of making images responsive but trying to do so with this combination is taxing my little grey cells and patience!
<figure class="iHolder">
<img width="499" height="340" src="stimages/image006.jpg" alt="The Great Pit">
<figcaption>The Great Pit (Excavated c.1534-1540)</figcaption>
</figure>
Without hard coding a set width in the css it’s difficult, or you hack it by adding <br>s to the caption.
On the last example I tried a attribute value in the css (was worth a try). That may work if you added a custom data attribute to the parent figure if that’s an option.
I had the same problem and adopted the fixed width div approach with a maximum image height above the title. The thumbnails look ragged with varying title lengths… no easy solution I’m afraid
If you set the table to 1% (which is needed to contain the caption to image size) then you can’t set the image to a percentage width because 100% will equal 1%.
You could either set a 20% (or similar) width for the table and have all images the same responsive size to start with. If you want natural widths but then allow the image to scale smaller you could use calc based on viewport width and end up with something like this:
The image will display at the natural size but when the viewport is the same size as the image the image will scale smaller.