HTML / CSS - Why is float: left render as "invisible"?
If you have two divs contained in a div:
<div style="border:1px;"> <div style="float:left;background-color:red;width:20px;height:20px;"> <div style="float:left;background-color:red;width:20px;height:20px;"> </div> The two inner divs are displayed as βinvisible,β since the div does not stretch in the container so that they can fill as if they were not there. This creates ugly matches / spaces, etc.
How do you solve this problem?
+4
6 answers
Try adding <br style="clear:both"/> , (or clear left), this is the usual method to give life to floating elements in the container
<div style="border:1px;"> <div style="float:left;background-color:red;width:20px;height:20px;"> ... </div> <div style="float:left;background-color:red;width:20px;height:20px;"> ... </div> <br style="clear:both"/> </div> +2
Is there a reason why you cannot / cannot put any content in a div? They overlap / appear invisible because there is no content.
<div style="border:1px;"> <div style="float:left;background-color:red;width:20px;height:20px;"></div> <div style="float:left;background-color:blue;width:20px;height:20px;"></div> </div> Show two divs next to each other (tested IE6, Chrome 3, Firefox 3.5, IE7)
0