Home » Programming / Coding

1px Gap in IE6 For Absolute Position Elements

25 January 2009 2,440 views No Comment

Ever wonder why web developers hate IE? Because Microsoft IE team seem to be intentionally disobey the browser standards. Lot of people believe Microsoft do it intentionally; and I am on their side as well.

If you have an absolute position div placed with bottom style, IE might show the div element 1px above where it supposed to be. Here is a code example:

<html>
<head>
<style>
.header { position: relative; height: 149px;background:yellow; }
.absDiv { position: absolute; bottom: 0; background:red;}
</style>
</head>

<body>
<div class=’header’>
Bla Bla Bla
<div class=”absDiv”>La La La</div>
</div>
</body>

</html>

Problem

If you look at the output in IE6, you would see that absDiv appears 1px above the bottom of header div.

Fun part is it does not happen always. It happens ONLY if you have parent div has either width or height odd number.

Solution:

You can use any of these two approaches. There could be other solutions as well.

  1. You can define the parent div width and height even number.
  2. Instead of using bottom style for absolute positioning use top style.
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.