css - 如何使:focus,:active与:hover相同

标签 css css-selectors pseudo-class

有什么简单的方法可以使:focus&:active表现为:hover吗?

通常我写:

.class a:hover, .class a:active, .class a:focus {...}

但是我只想编写一个:hover规则,而:focus&:active看起来一样
.class a:hover {...}

最佳答案

当前在CSS2/3中没有更好的方法可以做到这一点。

但是,您今天可能想使用cssnext来使用 @custom-selectors :matches() 语法。

使用自定义选择器:

@custom-selector :--enter :hover, :focus, .active;

a:--enter { ... }

与:matches()
a:matches(:hover, :focus, .active) { ... }

关于css - 如何使:focus,:active与:hover相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32620429/

相关文章:

css - Element.but 选择器 CSS

jQuery .remove() 和最后一个子项未按预期工作

internet-explorer - 使用 :not() pseudo-class in IE7/IE8

css - toastr js插件和css颜色变化

css - 变换旋转和平移圆形图像到另一个图像内

jquery - 对 CSS3 如何显示文本感到困惑

html - CSS 表单输入[type ="text"] 选择器

css - css中可以使用多个伪元素吗?

css - 为什么不能将特定于供应商的伪元素/类组合到一个规则集中?

javascript - 忽略 div 内的标签,直到被点击