【问题标题】:How can I caption an image inside a paragraph <p>?如何在段落 <p> 中为图像添加标题?
【发布时间】:2013-09-28 20:06:01
【问题描述】:

在过去的三个小时里,我试图弄清楚如何在段落中正确地为浮动图像添加字幕。我发现许多网站都涉及为图像添加字幕的任务,但没有一个网站涉及在段落中为图像添加字幕。这里的交易破坏者是无法在 p> 中包含除 em>、strong>、img> 等元素之外的元素。处理段落中的图片说明的最佳做法是什么?

我准备了一个jsfiddle:http://jsfiddle.net/cm94k/

谢谢

使用的html:

    <h3>I want the red "kitten"-caption to be generated with html/css. (This one is in the image!)</h3>
<p>
 eginning of the paragraph, but the end-tag  is optional. Nevertheless, consistently including the end-tag is a good practice, and make certain types of automated processing easier. More importantly, it helps to make explicit 

    <img class="capimg" src="http://tinyurl.com/ppy7cuk" />    

exactly where your paragraph really ends, which may differ quite significantly from where you as an author would have it. The ambiguity arises from the fact that HTML prescribes quite rigidly which elements may nest inside other elements. The only things that    
</p>

使用的css:

p {
    -moz-column-count:3; /* Firefox */
    -webkit-column-count:3; /* Safari and Chrome */
    column-count:3;
    -moz-column-gap:2em; /* Firefox */
    -webkit-column-gap:2em; /* Safari and Chrome */
    column-gap:2em;

}

.capimg {
    float: left;
    width: 33%;
}

【问题讨论】:

    标签: html css captions


    【解决方案1】:

    http://jsfiddle.net/QxqL4/6/

    我过去处理此问题的方法是将图像包装在 &lt;span&gt; 中并浮动该元素。您应该能够在图像之后添加文本,但仍然在 &lt;span&gt; 内而不会出现问题。

    唯一需要注意的是您需要指定&lt;span&gt; 的宽度。由于您的图像可能会有所不同,我建议内联执行此操作,将&lt;span&gt; 设置为与图像的宽度相匹配。

    <span class="capimg" style="width:200px;">
        <img src="http://tinyurl.com/qzxz95c" />
        This is what I would consider in terms of captioning. It should handle pretty much any length of text.
    </span>  
    

    【讨论】:

    • 这看起来不错。谢谢你。不过,我需要适应流畅的布局,因此使用 img-width 的百分比值。- 固定宽度不起作用。
    • 好吧,我给了 span 33% 和里面的 img 100%,这似乎工作得很好!谢谢你! jsfiddle.net/cm94k/7
    猜你喜欢
    • 1970-01-01
    • 2012-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多