How can I caption an image inside a paragraph

?


Tags: html,css,captions

Problem :

I spent the past three hours trying to figure out how to properly caption floated images inside paragraphs. I found numerous websites covering the task of captioning images, but none of them were dealing with captioning an image inside a paragraph. The deal breaker here is the inability to have elements other than em>, strong>, img> and such within p>. Whats the best practice to handle image captions in paragraphs?

I prepared a jsfiddle: http://jsfiddle.net/cm94k/

Thank You

html used:

    <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 used:

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%;
}


Solution :

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

The way I have handled this in the past is to wrap the image in a <span> and float that element. You should be able to add text after the image but still inside the <span> without issue.

The only caveat is that you need to specify the width of the <span>. Since your images may vary, I would suggest doing this inline, setting the <span>'s with to match the width of the image.

<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>  

    CSS Howto..

    How to create a caption for a pure CSS/HTML Slider with thumbnails, no java/jquery

    How to stop CSS cascading or how to target only 2nd child and not 3rd with CSS

    How can i expand the content through css?

    2 Sidebar Columns Layout (How)?

    How to move the POV of an image when using overflow: hidden?

    How do you modify wordpress css for posts?

    How to convert a JSON object (created by jquery-css-parser) back to valid CSS code? [closed]

    How to toggle visibility of 2 divs after clicking a mailto link?

    How to change CSS attribute at all div inside td with class

    CSS: How to shorter code having select direct children with multiple id

    How to enable CDN CSS in Brackets, Chrome?

    How to make a img flicker using css(should work in all browsers)

    How to highlight table row on hover using CSS only?

    How do you set a css class attribute with Javascript? [duplicate]

    How to set a CSS property with a variable in JQuery?

    How can override a CSS class to that nothing get applied?

    how to minify css file containing @page

    How do I update an div css to display an complete image when section is complete?

    How to use CSS to create the left - right alignment so the left div does not push the right div

    How to change content of css using jQuery toggle

    How to make a border in css that is actually on the very edges

    meteor: how to use multiple classes in css selector

    How to get all select element in JQuery

    HTML/ CSS: A href exceeds linking image - how to avoid?

    How can I make an unclickable HTML “Ghost” Div?

    How to get equal height for all sections?

    CSS: how to make two sections at the same line?

    Jquery: How to check if the element has certain css class/style

    How-to mix fixed and percentage heights/width using css without javascript

    How do I get rid of this blue halo around the close dialog button with jqueryui?