Hey, I'm trying to make a float image with captions: div.image { float: left; padding: 0 4px 0 0; } div.image p { margin: 0; text-align: center; font-size: smaller; } And using it as such: <div class="image"> <img src="http://www.myimage.com/myimage.jpg" alt="pic"/> <p>This is my caption, which is very very very very very very very very very very very very longing. (Yes I typed each of those very's).</p> </div> However, I'd like the caption to wrap within the bounds of the image width...which is not fixed or known. How would I go about this?
Here's a guess: If you set no width at all, the float is supposed to shrink wrap. However, I think they don't in FF or IE. Only Opera and Safari seem to follow this spec. For IE7 and FF you might be able to get away with a max-width setting (find the largest image and use that as a benchmark). Max-width is not considered a width declaration so the float should still shrinkwrap.
Thanks, the max-width works great. Just put: div.image p { max-width: 99%; } and it doesn't matter what the size of the image is, the text will wrap accordingly.
Add a width for IE6 because it doesn't understand anything other than width: * html div.image p { width: 99%; } Duh I should have thought of the p as a child cause then of course it can't go wider than its parent whatever the width... usually the most-obvious answers are the ones I don't see for the longest time.