I have HTML:
<figure style="display:inline-block;">
<img src="https://i.imgur.com/k1Crowy.jpg" width="200">
<figcaption> This is some random text that should not expand the figure tag beyond the width of the img tag </figcaption>
</figure>
I want the <figure>
tag to have the width of the <img>
tag, which works just fine.
The problem is the content of the <figcaption>
tag expands the width of the <figure>
tag. How can I make it so the <figcaption>
will be limited to the width of the <img>
tag. So 200px
in above example.
I can't edit the HTML. Can only adjust CSS.
What I've tried so far
position:absolute
approach on<figcation>
. Problem is that it won't expand the height of the<figure>
tag.- Obviously, I can set a fixed width to
<figure>
tag (likewidth:200px
), but I can't predict the width of the image. - jQuery approach where I grab the width of the image and add it to the
figure
tag. But I want to avoid a JS solution.