CSS and IE: clear

I always have a clear class in my CSS to clear any floating elements:

.clear { clear: both; }

And commonly used in html code such as follows:

<div id="floating_1">something</div>
<div class="clear"></div>
<div id="floating_2">something</div>

If defined correctly, the expected behavior would be 2 floating elements sticking together. However when viewed from IE, there’s a block of white space in between the 2 elements. This is because IE doesn’t not render the property correctly.

The fix

Add visibility to the class:

.clear { clear: both; visibility: hidden; }

Theorectically elements with visibility set to hidden still occupies the space in the layout. But in IE it works as if set display to none! It’s IE so we don’t expect it to behave in accordance to standards.

Leave a Reply

Your email address will not be published. Required fields are marked *