I often find myself using code blocks for inline article images like the following:
...article text.
<div class="article-image right" style="width: 250px;">
<img src="..." width="250" alt="" />
<p class="caption">Potentially long image caption</p>
</div>
More article text...
Or, the more succinct HTML5 version:
...article text.
<figure class="right" style="width: 250px;">
<img src="..." width="250" alt="" />
<figcaption>Potentially long image caption</figcaption>
</figure>
More article text...
Since I use a CMS that processes images on the fly, I've been defining the size of the image (250px in this case) dynamically, and I've also been applying that size restriction to the parent element that contains both the img
and its caption. This way, the caption never increases the size of the parent element beyond the defined width of the img
tag.
My question is if there is some CSS trick I can apply to one of the elements that will accomplish the same thing without manually defining the width? Some way to prevent the captions from expanding their parent element in width, yet allowing them to influence the height? Of course the parent element's width still needs to adapt to the img
's width...