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 1708 days 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 1708 days 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 1704 days ago

    Hey hey, very handy indeed!

  4. Nate Elmore said 1688 days ago

    Way cool.

  5. adt said 1650 days ago

    adt

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

  6. buy wii said 1625 days ago

    buy wii

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

  7. Alice said 1602 days 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 1595 days ago

    lv

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

  9. ftd said 1594 days ago

    ftd

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

  10. buy.com said 1592 days ago

    buy.com…

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

  11. adt said 1582 days ago

    adt

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

  12. limewire said 1576 days ago

    limewire

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

  13. sierra trading post said 1575 days ago

    sierra trading post

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

  14. atacand said 1568 days ago

    atacand

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

  15. ged said 1553 days ago

    ged

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

  16. ftd said 1551 days ago

    ftd

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

  17. ScottChavez said 1549 days ago

    totally sweeet man!!

  18. ged said 1543 days ago

    ged

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

  19. debt solutions said 1541 days ago

    debt solutions

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

  20. window curtains said 1536 days ago

    window curtains

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

  21. beds said 1536 days ago

    beds

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

  22. lv said 1535 days ago

    lv

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

  23. trojan condoms said 1535 days ago

    trojan condoms

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

  24. lv said 1534 days ago

    lv

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

  25. ergonomic chairs said 1531 days ago

    ergonomic chairs

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

  26. allstate insurance said 1521 days ago

    allstate insurance

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

  27. nordstrom said 1506 days ago

    nordstrom

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

  28. winmx said 1506 days ago

    winmx

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

  29. irs tax forms said 1506 days ago

    irs tax forms

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

  30. bloomingdales said 1506 days ago

    bloomingdales

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

  31. irs tax forms said 1506 days ago

    irs tax forms

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

  32. irs tax forms said 1506 days ago

    irs tax forms

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

  33. usana said 1506 days ago

    usana

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

  34. weight watchers said 1506 days ago

    weight watchers

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

  35. net10 said 1506 days ago

    net10

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

  36. pottery barn said 1506 days ago

    pottery barn

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

  37. ftd said 1506 days ago

    ftd

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

  38. pottery barn kids said 1506 days ago

    pottery barn kids

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

  39. fog lights said 1506 days ago

    fog lights

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

  40. easyjet said 1506 days ago

    easyjet

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

  41. eharmony said 1506 days ago

    eharmony

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

  42. netflix said 1506 days ago

    netflix

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

Sorry, the comment form is closed at this time.