I'm curious why using >
or other combinators does not affect the specificity of CSS selectors, i.e. why div span
(matching a span somewhere inside a div) and div > span
(matching a span which is the immediate child of a div) are considered equal regarding the specificity.
我很好奇为什么使用>或其他组合器不会影响CSS选择器的特异性,即为什么div span(匹配div内某处的span)和div> span(匹配div的直接子节点)在特异性上被认为是平等的
I do realize that the usage of combinators is completely irrelevant for the specificity but I wonder if there's a certain reason for it.
我确实意识到组合子的使用与特异性完全无关,但我想知道它是否有某种原因。
1 个解决方案
#1
8
This has actually been brought up in the working group mailing list, way back when, in this thread.
这实际上是在工作组邮件列表中提出的,在这个帖子中回来的时候。
It basically comes down to, yes, intuitively a selector with a combinator looks more specific, but an algorithm, extended form the current one, with this in mind becomes much more complicated than the "simple" triplets used now, which is pretty confusing for people as it is.
它基本上归结为,是的,直观地说,一个带有组合器的选择器看起来更具体,但是一个从当前扩展的算法,考虑到这一点变得比现在使用的“简单”三元组复杂得多,这非常令人困惑。人们就是这样。
Finally,
While this could have been the case, this is one of the few things in CSS2 that have been interoperably implemented for years, and therefore won't change in CSS2.1.
"If it ain't broke, don't fix it." seemed to be the final call.
“如果没有破产,请不要修理它。”似乎是最后的决定。
#1
8
This has actually been brought up in the working group mailing list, way back when, in this thread.
这实际上是在工作组邮件列表中提出的,在这个帖子中回来的时候。
It basically comes down to, yes, intuitively a selector with a combinator looks more specific, but an algorithm, extended form the current one, with this in mind becomes much more complicated than the "simple" triplets used now, which is pretty confusing for people as it is.
它基本上归结为,是的,直观地说,一个带有组合器的选择器看起来更具体,但是一个从当前扩展的算法,考虑到这一点变得比现在使用的“简单”三元组复杂得多,这非常令人困惑。人们就是这样。
Finally,
While this could have been the case, this is one of the few things in CSS2 that have been interoperably implemented for years, and therefore won't change in CSS2.1.
"If it ain't broke, don't fix it." seemed to be the final call.
“如果没有破产,请不要修理它。”似乎是最后的决定。