请考虑以下示例:
<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的方法使标题采用可在大多数浏览器上使用的图像宽度,所以请不要出现边缘css的麻烦?
编辑:没有固有宽度(最小含量)的解决方案。
编辑:我在图形下方添加了文本,该文本也应在标题下方。
更新的代码https://jsfiddle.net/harshapache/sLeab4zg/
figure {
position: relative;
display: table-caption;
}
figure{
display: table;
width: 1px;
}