html - css:每个类都支持:悬停状态吗?

标签 html css

如果我为一个普通的 div 使用一个类,我可以这样写 css 吗:

.messagebc:hover {
...
}

合法吗?

最佳答案

在非链接元素上使用 :hover 是低效的。

避免为 IE 客户端的非链接元素使用 :hover 伪选择器。

If you use :hover on non-anchor elements, test the page in IE7 and IE8 to be sure your page is usable. If you find that :hover is causing performance issues, consider conditionally using a JavaScript onmouseover event handler for IE clients.

:悬停非链接元素的伪选择器是一个非常低效的选择器(例如): 例如:

h3:hover {...}
.foo:hover {...}
#foo:hover {...}
div.faa :hover {...}

众所周知,非 anchor 元素上的 :hover 伪选择器在某些情况下会使 IE7 和 IE8 变慢*。当不使用严格的文档类型时,IE7 和 IE8 将忽略 :hover 在除 anchor 之外的任何元素上。当使用严格的文档类型时,:hover 在非 anchor 上可能会导致性能下降。

More info on un-effiecient selectors

关于html - css:每个类都支持:悬停状态吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4204527/

相关文章:

html - ul 选择器有效,但不适用于 ul 的类

html - 页脚在小型设备上有边距底部

jquery - 数据表 - 在页面加载时,表格布局不会立即加载

html - MetroUI CSS 将图标显示为控制字符

css - 将悬停效果应用于 2 个 div

HTML header 问题。为什么会有间距?

javascript - PHP - URL 重定向奇怪的行为

css - HTML5 CSS 验证内容类型错误

javascript - 来自数组的随机颜色

html - 在 CSS 中,如果 border-radius 都属于同一个 div 标签,那么 border-radius 是否必须与它修改的边框属于同一个类?