I have made and image with a caption using CSS, but I am hoping someone
can show me how to do it better. By better I mean less HTML, and
hopefully have it work with any sized image where I do not have to hard
code the width of the container that holds the image.
Here is a description:
I want to have an image with a caption underneath, aligned on the left.
There should be a black keyline around the image, and the caption
underneath, and the caption needs a grey background color with white
text. Furthermore, the object (image and caption together) needs to
have a margin on the top, right, and bottom so the body text can wrap
around it.
Here is my current HTML:
<div style="float: left; width: 436px;"><!-- width=image width(414)
+ right-margin(20)
+ img border(1+1) = 436
-->
<div class="image_left"><img src="../images/some_pic.jpg"
width="414"></div>
<div class="caption_left"><b>image caption</b> - Blah, blah,
blah...</div>
</div>
Here is my external stylesheet:
DIV.image_left
{ BORDER: 1px solid #000000;
MARGIN-TOP: 10px;
MARGIN-RIGHT: 20px; }
DIV.caption_left
{ BORDER-TOP: 0px;
BORDER-LEFT: 1px solid #000000;
BORDER-RIGHT: 1px solid #000000;
BORDER-BOTTOM: 1px solid #000000;
MARGIN-RIGHT: 20px;
MARGIN-BOTTOM: 5px;
PADDING: 3px;
BACKGROUND-COLOR: #666666;
COLOR: #ffffff;
FONT-SIZE:80%;
WHITE-SPACE: wrap; }
It all works and look ok, but like I said, I hate having to hard code
the main DIV ("width: 436px"). Is there a way to get it to work
without this hard-coding, based on the width of the image (which is
dynamically pulled from a database.) And can someone do it so there is
less HTML (CSS size does not matter)?
Thanks! I am an ASP/PHP programmer, and my CSS knowledge is not my
strength...
aqualizard