在CSS中组合伪选择器? [英] Combining Pseudo-selectors in CSS?

查看:75
本文介绍了在CSS中组合伪选择器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的意思是,如果我需要,例如,在悬浮链接中选择的文本是红色的,我可以在CSS样式中使用下面的代码?

I mean if I need, for example, selected text in a hovered link be red, could I use the following code in CSS style?

.abc:hover:selection{color:red}

<a href="123" class="abc">4567890</a>

当我选择它的一部分时,链接,当我悬停它时变成红色,正确的语法为这样的伪类组合?

Would that link, when I select part of it, become red colored when I hover it and is this correct syntax for such pseudo-classes combining?

推荐答案

如果你在谈论伪类,

除了在这种情况下, :: selection 不是伪类,伪元素不是CSS1或CSS2的一部分,或任何当前规格的事情。这是伪选择器这个术语的缩写,因为它们是两个完全不同的东西。

Except in this case, ::selection is not a pseudo-class, it's a pseudo-element that's not part of CSS1 or CSS2, or any current spec for that matter. And this is where the term "pseudo-selector" falls short, because they're two completely different things.

正确的语法是:hover 和双冒号 :: selection ,与伪类不同,伪元素必须总是最后:

The correct syntax is a single colon for :hover and double colons for ::selection, and unlike pseudo-classes, pseudo-elements must always come last:

.abc:hover::selection{color:red}

即使如此,由于 :: selection 的工作原理(或不是),在浏览器中的效果。

And even then, because of the way ::selection works (or doesn't), it's not guaranteed to actually have an effect in browsers.

这篇关于在CSS中组合伪选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆