§ ITPOW >> 文档 >> CSS

haslayout 引起的 IE6 :hover 失效

作者:愚人码头 来源:WEB前端开发 日期:2009-5-31

大家都知道 IE6 支持 <a> 标签的 :hover,但是通常在做实际效果的时候 <a> 标签 :hover 在 IE6 下会失效,看代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
a:hover { }
a:hover span{color:#F00;}
</style>
</head>
<body>
<a href="#">鼠标经过时改变我的<span>颜色</span></a>
</body>
</html> 

在 IE6 下“颜色”根本就不会变成红色,其他浏览器都是好的,要解决这个问题就必须触发 a:hover 的 layout,例如 a:hover { display:inline-block} 或者 a:hover { zoom:1} 等等。

(display:inline-block 表示行内块元素,为 CSS 2.1 新增内容。ITPOW编辑注)

相关文章