Hello–I’m trying to set up a container using <DIV> tags that will expand or contract vertically based on what’s inside. Using the code below, it works for text, but if it’s just an image (or if the image is “taller” than the text), the image overflows the bottom border of the container.
The problem is that you are floating the image. When you float something, it takes it out of consideration for parent container sizes (if the parent doesn’t float). In your case, I think just left aligning the image may give you the result you want without the ugly side effect of floating.
Thanks for the suggestion! However, it seems like the image still wants to protrude from the bottom of the container. Here’s the <img> tag with the change so you can see what I did:
Any ideas? I’m wondering if it’s the <p> tags that keep the text from running out the bottom of the box, and if so whether I could try putting the IMG in its own <p> tags. Seems like this might cause other problems…
Thanks again, and let me know if you have any other suggestions.
Or depending on the situation you could add this instead:
#content {overflow:auto}
Floats are removed from the flow and will float out of their parents containers unless you have cleared the float with something solid or used one of the many clearing techniques around.
See the faq on floats as it goes into detail on this issue and you will need to understand it fully before you can move on to other things