我正在对一个 CSS 元素进行样式化,我想知道我是否可以在一个 CSS 元素上使用多个 :selectors
。
例如:
p:hover:after {
content: "Hello!";
}
因为,当我希望 p
悬停时,我希望 :after
选择器也被调用。
最佳答案
那个具体的例子是完全有效的,它的作用是demonstrated here .
到目前为止,关于伪元素的主要限制是:
CSS3 Selectors - 7. Pseudo-elements (reference)
Only one pseudo-element may appear per selector, and if present it must appear after the sequence of simple selectors that represents the subjects of the selector. Note: A future version of this specification may allow multiple pseudo-elements per selector.
因此,以下选择器都不起作用:p:hover:after:after
、p:after:hover
对于可以在选择器中链接在一起的简单选择器的数量没有限制。而作为 @BoltClock states评论中只能有一个类型选择器或通用选择器。
CSS3 Selectors - 4. Selector syntax (reference)
A sequence of simple selectors is a chain of simple selectors that are not separated by a combinator. It always begins with a type selector or a universal selector.
这里是一个相关的长选择器:(example)
#parent:first-of-type:first-child > .child:last-child p:not(#element):not(#otherelement):hover:after
关于html - 多个 :selectors on one CSS element?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19966260/