开发者

IE6 Hover Issue

The CSS :hover doesn't work in IE6 for elements that are not links. Is there a workaround? e.g. how do I apply the 开发者_JAVA技巧:hover to a div?


There's whatever:hover. I've never used it myself but from what I hear, it works well.

Whatever:hover is a small script that automatically patches :hover, :active and :focus for IE6, IE7 and IE8 quirks, letting you use them like you would in any other browser. Version 3 introduces ajax support, meaning that any html that gets inserted into the document via javascript will also trigger :hover, :active and :focus styles in IE.


You can use the famous IE7.js from Dean Edwards, which has the nice advantage, that you can use the :hover selector in your CSS.

Apart from that, I doubt that you can achieve it with CSS alone. IE can handle JS in CSS files via expression(), but you can't get to an expression to handle hovering without a selector handling hovering, if you catch my drift.

Then, finally, a short jQuery solution:

$(document).ready(function () {
  $('div').hover(function () {
    $(this).addClass('hover');
  }, function () {
    $(this).removeClass('hover');
  });
});

Then you can use this in your stylesheet:

div:hover, div.hover { ... }


  • If you only need for paticulars div and you are not using jquery then go for suckerfis js as @futta suggested.http://www.htmldog.com/articles/suckerfish/
  • If you are planning to use Hover on more tags in future and don't want to edit every time js for this the go for Whatever.htc in for IE6. as @Pekka suggested.
Suckerfish vs. .htc

IIIIN the blue corner we have Suckerfish, the original lightweight, accessible, cross-browser, standards-compliant :hover mimic. IIIIN the red corner we have '.htc' - the JavaScript files accessed via CSS to mimic :hover.

Ding ding!

And Suckerfish instantly lands a heavy blow on .htc's validity - .htc simply isn't standards compliant CSS.

Oooo... .htc sneaks in a crafty jab without the need for additional selectors...

Suckerfish bounces around the ring. He's much lighter weight than his opponent.

And OH! The IE 5.0 uppercut! That's something that .htc just doesn't have the skill to do, whereas Suckerfish can work IE 5.0 seamlessly.

.htc is dazed! And the contest is over! Suckerfish wins on points! TKO!

  • IF you want to get benefit for other things (other than Hover) also in IE then go for IE7.js as @Boldewyn suggested
  • And If you are already using jquery and want to use hover in a limited way then go for This way : How to enable hover on a div for IE6 using jquery in minmal code?

NO pure and valid CSS solution available for this in IE6.

  • One Non- valid CSS expression solution is available but i would not not advise to use this because it's slow

    Solution: http://www.visibilityinherit.com/code/ie6-hover-expression.php


suckerfish and it's offspring provde great lightweight alternatives for this purpose too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜