IE6对于hover()伪类的支持很不好,IE6只支持a标签的hover,其他的都不支持。Windows主机用csshover.htc,其实我们可以用JQuery解决IE6不支持CSS hover伪类这一问题。

我们很早就知道IE6对于hover()伪类的支持很不好,IE6只支持a标签的hover,其他的都不支持。

这也就导致了很多想使用hover效果在IE6下就失效了,本人很,非常,十分,特别,超级讨厌IE6,但是就目前中国看来用IE6内核的实在是搞的离奇,IE9 beta都出来了,怎么你们就这么喜欢用IE6,算了,不抱怨了,抱怨了也木有用。问题还是要解决的。

网上也有很多解决的方法,说的最多就是用csshover.htc,这是微软提供的一个指令组合,用这个可以轻松的实现IE6的hover,话说之前我用的都是这个,不过用WordPress之后,换了Linux主机,然后我就发现不支持这个了,然后有些小郁闷,然后我又想实现这样的效果,怎么办呢?当然是有办法的,用JQuery。越来越喜欢JQuery了,方便,兼容性好,效果多。

我做了一个简单的预览效果,文字hover与图片hover。

html head metaContent-Typetext/html;utf-8 / title JQuery解决IE6不支持CSS hover伪类[Linux主机] | 威言威语 /title scripttext/javascript src= http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js /script scripttext/javascript jQuery(document).ready(function($){$( .b ).hover(function() {$(this).css( background , url(weisay2.gif) no-repeat center bottom $(this).css( border , 1px #999999 solid },function(){$(this).css( background , url(weisay1.gif) no-repeat center top $(this).css( border , 1px #CCCCCC solid $( .c ).hover(function() {$(this).css( color , #00CC33 $(this).css( border , 1px #999999 solid },function(){$(this).css( color , #000066 $(this).css( border , 1px #CCCCCC solid /script styletext/css .c{color:#000066;border:1px #CCCCCC solid;}.c:hover{color:#00CC33;border:1px #666666 solid}.b{border:1px #CCCCCC solid;background:url(weisay1.gif) no-repeat center;width:80px;height:80px}.b:hover{background:url(weisay2.gif) no-repeat center;border:1px #666666 solid} /style /head body div >

将其复制保存下来,用IE6打开看效果。代码也很简单,一看就看懂了,注意class类的对应,

$(this).css( background , url(weisay2.gif) no-repeat center bottom $(this).css( border , 1px #999999 solid

是鼠标放上去的hover样式,

$(this).css( background , url(weisay1.gif) no-repeat center top $(this).css( border , 1px #CCCCCC solid

是没有鼠标经过的正常的样式,好了,我又啰嗦了。

通过这个代码,就可以轻松实现IE6的hover效果了。