【问题标题】:Display image caption on the bottom of the image在图像底部显示图像标题
【发布时间】:2018-05-20 08:07:55
【问题描述】:

我正在尝试在图片底部显示图片说明。

这就是我目前所拥有的。标题应该位于图像的底部并与其宽度相匹配。它不这样做的原因是因为包含图像的<figure> 没有调整大小以匹配图像。

<figure class="fig">
    <img src="http://such.url" class="fig__media"/>

    <figcaption class="image-caption-text">Some caption</figcaption>
</figure>

我做了一些搜索,发现通常您需要添加display: inline-block,正如建议的here。这在这里没有影响。我怀疑这是因为图像本身具有带有position: absolute 的CSS。如果我删除那个位,布局就会中断。 (不是我的 CSS,我也不是网络开发人员。)所以即使图像使用绝对位置,我似乎也需要一种方法来让 &lt;figure&gt; 调整大小。或其他方式来正确定位标题。

【问题讨论】:

    标签: html css figure


    【解决方案1】:

    我建议像position: absolute; 那样为figcaption 而不是img 那样figure 可以采用img宽度

    figure {
      border: 1px solid;
      display: inline-block;
      margin: 0;
      position: relative;
    }
    
    figcaption {
      position: absolute;
      bottom: 1em;
      left: 0;
      background-color: yellow;
      width: 100%;
    }
    <figure class="fig">
        <img src="http://placehold.it/500x200" class="fig__media"/>
    
        <figcaption class="image-caption-text">Some caption</figcaption>
    </figure>

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-21
    • 1970-01-01
    • 1970-01-01
    • 2020-09-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多