html - Figcaption 不比图像宽

标签 html css

我有一个问题,figcaptionimg 宽,因此突出到它的右边。我对标题的 width 进行了硬编码并且它有效,但仅适用于相同宽度的图像。

enter image description here

HTML

<figure>
    <img src="http://i.imgur.com/tVeUqlH.jpg"/>
        <figcaption>Vader enjoying the beach.</figcaption>
</figure>

CSS

figure {
    border: 1px solid black;
    display: inline-block;
    padding: 3px;
    margin: 10px;
}
figure img {
    vertical-align: top;
}
figcaption {
    text-align: center;
    border: 1px dotted blue;
    width: 120px;
}

jsFiddle

最佳答案

您可以使用display: table-caption;

.imagecaption {
    padding: 3px;
    margin: 10px;
    float: left;
    border: 1px solid black;
}
figure {
    display: table;
    margin: 0px;

}

figure img {
    display: block;
}

figcaption {
    display: table-caption;
    caption-side: bottom;
    text-align: center;
    border: 1px dotted blue;
}
<div class="imagecaption">
  <figure>
    <img src="http://i.imgur.com/tVeUqlH.jpg"/>
    <figcaption>Vader enjoying the beach.</figcaption>
  </figure>
</div>

关于html - Figcaption 不比图像宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28394007/

相关文章:

html - 定位/调整背景图片大小问题

javascript - 如何使div在html中相互拖动?

html - 伪元素裁剪

html - 如何在两个组件之间画线

javascript - 为什么这个下拉菜单在 IE 中不起作用?

php - 使用 html 表单在 ISO-8859-1 环境中发送波兰语字符

javascript - jquery或native无法通过ID获取元素

javascript - 有没有办法将 chrome 扩展移植到其他浏览器?

缩放框上方的 CSS 固定大小框

html - 删除选择框的所有填充