Display background behind a floating element

Posted by Stefan on Nov 19, 2008 in CSS |

Ok… so you setup a page with a blue background and float an object left, for example. You now see that the background colour on the float is white! Ruining the look of your page.

<div id=”contentBody”>
<div style=”float: left;”>Floated Content</div>
</div>

So how do we do it? Use the following hack:

#contentBody:after { content: “.”; display: block; height: 0; clear: both; visibility: hidden; } * html #contentBody { height: 1%;}

Reply

Copyright © 2009 Stefan Jagger All rights reserved.