My goal is to incorporate image captions on my website, but I've run into an issue with compatibility. Since the figure
tag isn't supported in old versions of IE such as IE8 or below, I'm considering using a <div>
containing an <img>
along with the caption.
The problem arises when the caption text is wider than the image itself. In this case, the width of the enclosing <div>
adjusts to match the width of the caption, creating unsightly white space next to the <img>
. Ideally, I'd like the caption to wrap over multiple lines instead.
I could manually set the width of the <div>
to be equal to the image's width, or add <br />
tags within the caption to force line breaks. However, I'm searching for a more elegant and efficient solution to this problem.
To better illustrate the issue, you can view an example on this jsfiddle link.