Log in

View Full Version : Image with caption



gemzilla
11-11-2013, 12:41 PM
I am trying to add a caption to an image. The way I have done it is by enclosing the image and caption text within a div tag. The problem is that the outer div will not wrap round the image unless I set a specific width, obviously. I don't want to set a width as I want to be able to use it on other images in the website that may have a different width. Is there a simple way of achieving what I want to do without the use of tables or java script. Below is the HTML and CSS that I'm using.

HTML




<div class="image">

<img src="Imageurl" />

<div class="caption">Description of image</div>

</div>



CSS




.image{
margin:5px;
height:auto;
}

.caption {
font-style:italic;
font-size:11px;
}