1

我花了三个小时试图弄清楚如何在段落中正确地为浮动图像添加标题。我发现许多网站都涉及为图像添加字幕的任务,但没有一个网站涉及在段落中为图像添加字幕。这里的交易破坏者是无法在 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%;
}
4

1 回答 1

2

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

我过去处理这个问题的方法是将图像包装在 a 中<span>并浮动该元素。您应该能够在图像之后添加文本,但仍然在<span>没有问题的内部。

唯一需要注意的是,您需要指定<span>. 由于您的图像可能会有所不同,我建议您这样做内联,设置<span>'s 以匹配图像的宽度。

<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>  
于 2013-09-28T20:16:59.403 回答