I’ve been extremely busy lately, but I ran across this gem in my earlier posts. I think that it deserves it’s own spotlight, so I’ve decided post it here. As we all know, IE6 has broken support for the CSS :hover pseudo class on any element but the a tag, which is highly needed for drop down navigation. And since IE6 will need to be supported by web design and development for years to come, we still have to face this issue. Many solutions will use a separate JavaScript file to add back the missing functionality, usually a .htc behaviors file. However, I will do no such thing. I just want this to be in my CSS. Let’s setup a scenario.

Suppose you have a nav structure, styled like this

div#nav ul li
/*rules go here...*/
}

Typically, you would also incorporate some sort of hover style, like so:

div#nav ul li:hover
/* hover rules go here...*/
}

As we know, this won’t work in IE6, so we need a solution.

Here’s what I use

* html div#nav ul li{
unicode-bidi: expression(
this.onmouseover = function(){this.className += ' hover';},
this.onmouseout = function(){this.className = this.className.replace('hover','');}
);
}

Basically, this will add a class name of “hover” to the currently hovered list item. Then, when the hover is happening on a different element, it will remove the hover class from that element and put it on the new hovered element. Please note, this is not a new idea. This is simply the small line of code I use that I thought others may like. Also, take note of the * html preceding the div#nav rules. This is a hack to apply this rule to only IE6, no need to apply to others.

So, to conclude, now your CSS would look like this

div#nav ul li:hover,
div#nav ul li.hover
/* hover rules go here...*/
}

Basically, remember that anytime you would use an li:hover pseudo state to make a change, also append a li.hover rule to target the IE6 version of the hovered link!

Well, thats it. I’m busy and gotta keep it short. Peace out.

Comments

42 Comments

  1. zimmi said over 3 years ago

    Ain’t it better to write #nav ul li a:hover. Supposing you have anchor inside the list – you have to, beacuse it is supposed to be navigation. No navigation with no links, he? :)

  2. Rogie said over 3 years ago

    @zimmi: Of course, but in the case of a drop down nav, you would have a scenario like this:

    <div id="my-nav">
    <ul>
    <li>
    <a href="#location" rel="nofollow">Go Here</a>
    <ul>
    <li>
    <a href="#sub-location" rel="nofollow">Sub Nav Link</a>
    <a href="#sub-location-2" rel="nofollow">Sub Nav Link 2</a>
    </li>
    </ul>
    </li>
    </ul>
    </div>

    So, as you can see if you use the a:hover to control the sub list display, you can’t, because the sub nav is in the list item, not within the link.

  3. Ben McNelly said over 3 years ago

    Hey hey, very handy indeed!

  4. Nate Elmore said over 3 years ago

    Way cool.

  5. adt said over 3 years ago

    adt

    http://topsearch.ifrance.com/adt adt

  6. buy wii said over 3 years ago

    buy wii

    http://webstore.webng.com/buy-wii buy wii

  7. Alice said over 2 years ago

    This is a very nice way to do dropdown with CSS! I’m going to try this out asap. Very neat, thanks for sharing.

  8. lv said over 2 years ago

    lv

    http://webtop4u.ifrance.com/lv lv

  9. ftd said over 2 years ago

    ftd

    http://topwebs4u.ifrance.com/ftd ftd

  10. buy.com said over 2 years ago

    buy.com…

    http://topwebs4u.ifrance.com/buy.com buy.com…

  11. adt said over 2 years ago

    adt

    http://onlineis.googlegroups.com/web/adt.html adt

  12. limewire said over 2 years ago

    limewire

    http://www.freewebs.com/wellweb/limewire limewire

  13. sierra trading post said over 2 years ago

    sierra trading post

    http://www.freewebs.com/freetopweb/sierra-trading-post sierra trading post

  14. atacand said over 2 years ago

    atacand

    http://livegroup.webng.com/atacand atacand

  15. ged said over 2 years ago

    ged

    http://www.geocities.jp/top16line/ged ged

  16. ftd said over 2 years ago

    ftd

    http://www.geocities.jp/top15webs/ftd ftd

  17. ScottChavez said over 2 years ago

    totally sweeet man!!

  18. ged said over 2 years ago

    ged

    http://www.geocities.jp/top8net/ged ged

  19. debt solutions said over 2 years ago

    debt solutions

    http://www.geocities.jp/net3top/debt-solutions debt solutions

  20. window curtains said over 2 years ago

    window curtains

    http://usuarios.lycos.es/topstore/window-curtains window curtains

  21. beds said over 2 years ago

    beds

    http://membres.lycos.fr/topwebs/beds beds

  22. lv said over 2 years ago

    lv

    http://beauty.geocities.jp/topbags3/lv lv

  23. trojan condoms said over 2 years ago

    trojan condoms

    http://membres.lycos.fr/topwebs/trojan-condoms trojan condoms

  24. lv said over 2 years ago

    lv

    http://membres.lycos.fr/topbags/lv lv

  25. ergonomic chairs said over 2 years ago

    ergonomic chairs

    http://usuarios.lycos.es/topstore/ergonomic-chairs ergonomic chairs

  26. allstate insurance said over 2 years ago

    allstate insurance

    http://members.lycos.co.uk/instores/allstate-insurance allstate insurance

  27. nordstrom said over 2 years ago

    nordstrom

    http://topsite.host93.com/nordstrom nordstrom

  28. winmx said over 2 years ago

    winmx

    http://topsite.host93.com/winmx winmx

  29. irs tax forms said over 2 years ago

    irs tax forms

    http://goodsite.host93.com/irs-tax irs tax forms

  30. bloomingdales said over 2 years ago

    bloomingdales

    http://topsite.host93.com/bloomingdales bloomingdales

  31. irs tax forms said over 2 years ago

    irs tax forms

    http://helpwebsite.freepimphost.com/irs-tax irs tax forms

  32. irs tax forms said over 2 years ago

    irs tax forms

    http://park.geocities.jp/usa_most/irs-tax irs tax forms

  33. usana said over 2 years ago

    usana

    http://topsite.host93.com/usana usana

  34. weight watchers said over 2 years ago

    weight watchers

    http://topsite.host93.com/weight-watchers weight watchers

  35. net10 said over 2 years ago

    net10

    http://topsite.host93.com/net10 net10

  36. pottery barn said over 2 years ago

    pottery barn

    http://topsite.host93.com/pottery-barn pottery barn

  37. ftd said over 2 years ago

    ftd

    http://topsite.host93.com/ftd ftd

  38. pottery barn kids said over 2 years ago

    pottery barn kids

    http://topsite.host93.com/pottery-barn-kids pottery barn kids

  39. fog lights said over 2 years ago

    fog lights

    http://topsite.host93.com/fog-lights fog lights

  40. easyjet said over 2 years ago

    easyjet

    http://topsite.host93.com/easyjet easyjet

  41. eharmony said over 2 years ago

    eharmony

    http://topsite.host93.com/eharmony eharmony

  42. netflix said over 2 years ago

    netflix

    http://topsite.host93.com/netflix netflix

Sorry, the comment form is closed at this time.