使字幕获得图像的宽度[重复]

问题描述 投票:0回答:2

请考虑以下示例:

<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的麻烦?

编辑:没有固有宽度(最小含量)的解决方案。

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

html css image width figcaption
2个回答
0
投票

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

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

0
投票
figure{ display: table; width: 1px; }
© www.soinside.com 2019 - 2024. All rights reserved.