是:not()否定接受后代选择器? [英] Does :not() negation accept descendant selectors?
问题描述
我一直在使用:not()
伪类来设置样式,而不需要使用第二个不必要的声明来覆盖第一个
,但现在我遇到一个奇怪的行为,Safari接受:not()
中的后代选择器,但Chrome不能。
I've been using the :not()
pseudo-class to style things without the need to override it with a second unnecessary declaration to undo the first one,
but now I came across a weird behaviour where Safari accepts descendant selectors within the :not()
, but Chrome doesn't.
我使用了 a:not(.blue a)
。
对于答案,但我仍然不完全明白的原因。
是后代选择器真的允许的规范吗?
I searched for answers, but I still don't fully understand the reason.
Are descendant selectors really allowed by the spec?
这里是一个演示: / p>
Here's a demo:
a:not(.blue a) {
color: red;
}
<div><a>this one should be in red</a></div>
<div class="blue"><a>this one shouldn't</a></div>
http://codepen.io/oscarmarcelo/pen/YqboQJ?editors=1100
推荐答案
在选择器级别3 ,答案是否定的。 :not()
符号只接受简单选择器
In Selectors Level 3, the answer would be NO. The :not()
notation accepts only simple selectors.
否定伪类:not(X)
是一个以
a 简单选择器(不包括否定伪类本身)作为
参数的函数符号。
The negation pseudo-class, :not(X)
, is a functional notation taking
a simple selector (excluding the negation pseudo-class itself) as an
argument. It represents an element that is not represented by its
argument.
什么是简单选择器?
从 selector syntax :
一个简单的选择器是一个类型选择器,通用选择器,属性选择器,类选择器,ID选择器或伪类。
A simple selector is either a type selector, universal selector, attribute selector, class selector, ID selector, or pseudo-class.
没有关于后代选择器的信息。
Nothing about a descendant selector.
,在选择器级别4 ,:not()
接受复杂选择器,其中包括后代组合器。对于此规范,浏览器支持仍然相当弱。
HOWEVER, in Selectors Level 4, :not()
accepts complex selectors, which would include descendant combinators. Browser support is still quite weak for this specification.
这篇关于是:not()否定接受后代选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!