Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Floating image to the left changes container div's height

Tags:

css

When I try to run the following:

​<div id="container">
     //This is a 200x200 image        
     <img src="http://dummyimage.com/200x200/CCC/000" />
</div>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

with CSS:

​#container {
    background:#000;
}

​I get a DIV with a black background container like I want.

However, when I add the following to the CSS:

#container img {
   float:left;
}

It seems like the container does not detect the image inside it and its height is set to minimum (can be seen here: http://jsfiddle.net/wc4GJ/ ).

How come floating the image to the left mess up the container DIV's height?

Thanks,

Joel

like image 819
Joel Avatar asked Oct 13 '10 08:10

Joel


1 Answers

Add overflow:auto; to #container

(Explanations below)

like image 155
MatTheCat Avatar answered Sep 22 '22 00:09

MatTheCat