Scripsit boclair:
>>I suppose this is too elementary. Contain the image and the
caption in a div with the same width as the image.
If the image with caption is to be floated, the div will take the
width of the image without it being actually declared on the div.
Yes, although in that case the width it takes on will be the maximum
of the image's width and the width of the caption (generally with no
line breaks if enough space is available). This is probably a good
thing though.
Yes. However more often than not, the image will need to be bordered
in which case the image needs to display block declared. This is what
I had in mind.
I don't quite follow. How would bordering affect this? Usually if you want a
border around an image, it's best to edit the image in an image processing
program, adding a border. But in any case, you can set a border for an image
in CSS (or HTML) without setting display: block.
And I think you would still have the problem that for
<div style="float: right">
<img ...><br>
caption text
</div>
the width would be determined by the caption text requirements, not the
image width, when the caption is longer than the image width.
So I think the only reasonable solution is to determine the width of the
image (via server scripting, if the page is more or less dynamic) and set
that width for the block.
I think I found a tricky way though...
<table width="1">
<tr><td><img ...></td></tr>
<tr><td>caption text</td></tr>
</table>
It's too tricky though, and there's no guarantee of success.
--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/