使标题占据图像的宽度

Make caption take width of image

考虑以下示例:

<figure>
  <img height="100px" src="https://upload.wikimedia.org/wikipedia/commons/d/d9/Test.png">
  <figcaption>Very long caption that should take the width of the image</figcaption>
</figure>
<div>This text should appear below the whole figure</div>

是否有一种 css-only 方法可以使标题采用适合大多数浏览器的图像宽度,所以不请不要流血 css?

编辑:没有固有宽度的解决方案(min-content)。

编辑:我在图下方添加了文本,该文本也应在标题下方。

figure{
    display: table;
    width: 1px;
}

更新代码 https://jsfiddle.net/harshapache/sLeab4zg/

   figure {
      position: relative;
      display: table-caption;
   }