views:

2968

answers:

3

I apologize for the headline, I don't really know a better way of putting it (let me know if you have a better way, I will change it). Please consider the following code:

<html>
<head>

 <title>IE 6 Menu Test</title>

 <style type="text/css">
  .nMenu {
   border:1px solid black;

  }    
   .nMenu ul {
    margin: 0;
    padding: 0;
    list-style-type: none;
   }

   .nMenu a {
    display: block;
    padding: 3px 0px 3px 5px;
    background-color: #fff;
    border-bottom: 1px solid #eee;
    font-weight:bold;
    text-decoration:none;
   }

   .nMenu a:hover {
    background-color: #dddddd;
   }
 </style>

</head>
<body>

 <div class="nMenu">
  <ul>
   <li><a href="">One</a></li><li><a href="">Two</a></li><li><a href="">Three</a></li><li><a href="">Four</a></li><li><a href="">Five</a></li>
  </ul>      
 </div>

 <hr />

 <div class="nMenu">
  <ul>
   <li><a href="">One</a></li>
   <li><a href="">Two</a></li>
   <li><a href="">Three</a></li>
   <li><a href="">Four</a></li>
   <li><a href="">Five</a></li>
  </ul>      
 </div>

</body>

In firefox, both the top and bottom menus display exactly the same. But in IE6, the bottom version, which is identical to the top except for the carriage returns after each list element, displays with extra padding above each element. The top version, without the carriage returns does not. This is especially apparent (the extra padding) when rolling over the items in the bottom list.

It seems that IE6 is rendering the carriage returns for some reason. For now we have just resorted to formatting our code like the top example, but this is less than ideal. Is there something we can put in the CSS to make this look proper in IE6?

+1  A: 

I don't have a solution to the main issue, but you could change your code formatting to look nicer and still work in IE 6.

<div class="nMenu">
    <ul>
        <li><a href="">One</a></li
        ><li><a href="">Two</a></li
        ><li><a href="">Three</a></li
        ><li><a href="">Four</a></li
        ><li><a href="">Five</a></li>
    </ul>                                           
</div>
David Kolar
Interesting approach - wonder if whitespace inside tags is accepted by the W3C validator.
Ross
This is an interesting approach, and while potentially more readable, I would say it is less maintainable. I would rather see no carriage returns I think.
Ryan Guill
Yes, it is certainly less than ideal, but then again so is dealing with IE 6. ;)
David Kolar
A: 

Try adding overflow: hidden; to .nMenu li.

Ross
I want to make sure I understood you right, I added:.nMenu li{ overflow: hidden;}to my css at the top. But this doesn't seem to change anything in IE6. Did I misunderstand?
Ryan Guill
That's what I meant, but strange it didn't work. Try adding it to the a instead.
Ross
same thing when adding it to the a.
Ryan Guill
+5  A: 

Apply display: block; to the li, tell IE6 to make the a 100% in width, and tell all browsers to display the a as a block instead.

.nMenu li {
    display: block;
}

/* hack for IE6 */
* html .nMenu a 
{
    width: 100%
}

.nMenu a {
    display: block;
    padding: 3px 0px 3px 5px;
    background-color: #fff;
    border-bottom: 1px solid #eee;
    font-weight:bold;
    text-decoration:none;
}

Tried it in IE6 and both lists look identical, and renders exactly the same in Firefox.

baxter
This works to remove the extra whitespace above and below, but does not put the background-color on the entire row on hover like it does when the class is applied to the <a>.
Ryan Guill
Applying display:block to a split li element for IE into two parts: link block and empty text element, one on top of another. With block applied to li, you have block around your link followed by an empty text.
buti-oxa
Not sure what you mean buti-oxa. Could you provide an example?Ryan, I've corrected my example above, hopefully this should do the trick. You can replace my IE6 hack with any IE6 hack :)
baxter
I just explained why *your* solution works. (I was afraid it looks like magic to a reader.) MS Developer Toolbar showed me what IE "had in mind".
buti-oxa
Ah, hehe, I misunderstood you ;) thanks for the explanation!
baxter
Yes, this solution works perfectly.
Ryan Guill