IE6 Whitespace Bug

Word Count: 580

The better I get at css (and I am getting better) I really start to understand designers hatred for IE. I guess I always knew it on some level but when you are really trying to write clean code it starts to upset you that you have to hunt down IE6 specific bugs. My advise to everyone working with css is to get your layout/design working in a standards compliant browser and then double back to find out what bugs you need to fix. The bug I came across today (I have before but this is a great fix) is the IE Whitespace bug.

I was trying to create a block level list elements for a navigation like flow. When you use the code below and check the output in FireFox everything is exactly how you want it. In IE though there is extra space between elements. Here is the code and what it looks like in both browsers. The one on the left is FF and the right is IE6.

<html>
<head>
   <title>Lists Example</title>
   <style>
   #navigation {
      width:200px;
   }
   h3 {
      margin:0px;
      padding:0px;
      border-bottom:1px dotted #272727;
   }
   ul {
      margin:0px;
      padding:0px;
      list-style-type:none;
   }
   li a {
      color: #759398;
      text-decoration: none;
      padding-top: 4px;
      padding-right: 0px;
      padding-bottom: 4px;
      padding-left: 2px;
      display: block;   
      border-bottom:1px dotted #272727;
   }
   li a:hover {
      text-decoration: none;
      background-color: #132022;
      color: #ffffff;
   }
   </style>
</head>
<body>
   
   <div id="navigation">
   <h3>Navigation</h3>
   <ul>
      <li><a href="##">Menu Item 1</a></li>
      <li><a href="##">Menu Item 2</a></li>
      <li><a href="##">Menu Item 3</a></li>
      <li><a href="##">Menu Item 4</a></li>
      <li><a href="##">Menu Item 5</a></li>
      <li><a href="##">Menu Item 6</a></li>
      <li><a href="##">Menu Item 7</a></li>
      <li><a href="##">Menu Item 8</a></li>
      <li><a href="##">Menu Item 9</a></li>
      <li><a href="##">Menu Item 10</a></li>
   </ul>
   </div>

</body>
</html>

One solution to the problem I found that I really like was hicksdesign.co.uk. After reading through the comments though some users pointed out that the css may not validate so I ended up going with a solution from the comments. Placing the following code in your css will fix the problem and the css will validate. The final outlook looks good in all the browsers that I tested.

<style>
* html ul li a {
   height:1em;
}
</style>

Comments

#1 Posted By: joshua cyr Posted On: 12/27/07 1:32 PM
I like using zoom:1 myself. I have also run into a different whitespace issue with nested list items. The solution below isn't related to the haslayout bug, but seems to do the trick. No clue why though.

ul, li, li a { vertical-align:bottom;}

http://www.usefulconcept.com/index.cfm/2007/12/3/I...
#2 Posted By: Dan Vega Posted On: 12/27/07 1:35 PM |
Author Comment
Joshua,
That solution makes sense as well. I believe there are many solutions out there. The ultimate solution will hopefully come in the form of a standards compliant IE :)
#3 Posted By: John Posted On: 12/27/07 3:11 PM
I love me some Flex/Flash for that very reason. I use to care about validation, and the whole standards compliant thing, but I am starting to think its a waste of time. How many years have standards been around now, and we are still where we were 12 years ago...Hacking several versions of the same site for each browser. I hated dealing with it back then, and I hate it now. I don't think IE will ever be fully compliant because its not Microsofts style.

I do the opposite for css, I build for IE6 first. My server reports show most people (not designers) still use IE6 or 7. I get those dialed in perfect, and then hack for standards compliancy. After years of the opposite, I tried it, and it took me half the time. It's worth giving it a go sometime.

Great post, and great hack. I just ran across your site and I am liking what I have found.
#4 Posted By: Dan Vega Posted On: 12/27/07 3:34 PM |
Author Comment
John,
Thanks for the feedback. I guess you really could take it on a case by case basis. For example when working on my site analytics tells me the 54% of my visitors are firefox users while of the 38% that are IE users use 7.0. Everyone has their way of doing it but I just feel that if you create for standards first then you actually learn what code does what! Thanks for reading!
#5 Posted By: Christian Ready Posted On: 12/27/07 6:49 PM
It appears you have encountered the infamous hasLayout bug. Using zoom:1 is a pretty easy way to fix this.
#6 Posted By: Matt Leichty Posted On: 1/17/08 7:42 PM
I found in one case that I had that only using BOTH of these allowed it to work:

ul#myelement li {
vertical-align: bottom; zoom: 1;
}

Dropping either declaration caused a rendering problem, albeit not the same problem. Doing both fixed it. Why? Who TF knows.
#7 Posted By: TWD Posted On: 2/13/08 5:04 PM
I had a similar problem; after scouring the internet for help, I found one comment that IE6 adds whitespace in LIs. When I ran them together without any spaces or line breaks in the code the extra space disappeared.
#8 Posted By: Joel Pittet Posted On: 3/25/08 8:34 PM
joshua cyr: your solution saved my ass! Thank you, thank you! I am thinking of using this where ever I can as well, http://www.savethedevelopers.org/
#9 Posted By: El John Posted On: 3/28/08 1:38 AM
Great Job!!!
#10 Posted By: Chris M Posted On: 5/12/08 4:39 PM
<style>
* html ul li a {
height:1em;
}
</style>

Awesome fix, thank you so much!!
#11 Posted By: Nils Hendriks Posted On: 9/2/08 9:13 PM
* html ul li a { height:1% !important; } works all the time, but without the !important bits there are times it will still have the whitespace.
Note that 1% also works, just like 1 em;
#12 Posted By: Jon Dear Posted On: 2/27/09 8:00 PM
Thanks a lot. I spent all day trying to stop ie6 and 7 flickering on hover in a nav menu, and from increasing vertical padding, and changing left right widths.

This worked on ie6: * html ul li a {height:1em;}
This worked on ie7: ul, li, li a {vertical-align: bottom; zoom: 1;}
#13 Posted By: Meir Posted On: 3/8/09 8:39 AM
Great fix. I've been suffering this for years, thanks a lot!
#14 Posted By: Dimitris Posted On: 7/23/10 8:33 AM
+1 Thank you indeed!


Post Your Comment

Leave this field empty







Show Captcha

If you subscribe, any new posts to this thread will be sent to your email address.

Copyright © 2007 Dan Vega | BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.