How to remove the extra space added by IE browser on div tags

I just want to put an image inside a div like this:


<div>
<div>
<img src="image.jpg" alt="Image" />
</div>
</div>


Seems easy right? Unfortunately, it took me 15 minutes to figure out that the IE browsers are inserting an extra space in the bottom, just after the image. And whatever margin or padding values I set, it's useless.

Conclusion:
IE treats line-break as whitespace so you better remove it. Or put an empty comments inside the div and IE will not put extra space.

So the final tags are:

<div>
<div><!-- empty --><img src="image.jpg" alt="Image" /></div>
</div>
How to remove the extra space added by IE browser on div tags How to remove the extra space added by IE browser on div tags Reviewed by czetsuya on Sunday, April 05, 2009 Rating: 5

No comments:

Powered by Blogger.