August 31st, 2003, 05:30 AM
CSS: Control width of div with specific child element
This may be impossible, but I thought I would ask:
I am trying to set the width of a div element based on the size of an image that is within the div. Normally this isn't a problem, without a width being defined, the div will dynamically fit around the size of the image. However, I also have a text caption below the image in this same div and if the line goes longer than the width of the image than the div will be resized so that it doesn't fit so nicely around the image.
I don't want to define the width of the div because the image contained will vary in size.
I want to be able to specify that the div should only be as wide as the image and force the text to break and start new lines below rather than expanding the width of the div.
So i want to specify which child element controls the parent.
Is this possible in any way? If so, I'd love to know. Thanks in advance
being used for the photo caption here:
September 1st, 2003, 12:52 AM
not a very good solution but you can use a nested table there with width set to 1 to hold the image and caption.