为什么“foo bar”会这样?和'foo>酒吧' CSS 有同样的特殊性吗?
我很好奇为什么使用 >
或其他组合器不会影响 CSS选择器的特异性,即为什么div span
(匹配div内某处的span)和分区> span
(匹配 div 的直接子级的 span)在特异性方面被认为是相等的。
我确实意识到组合器的使用与特异性完全无关,但我想知道是否有一定的原因。
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这实际上已经在工作组邮件列表中提出了,早在 此线程。
它基本上可以归结为,是的,直观上带有组合器的选择器看起来更具体,但是从当前算法扩展而来的算法,考虑到这一点变得比现在使用的“简单”三元组复杂得多,这对于人们就这样。
最后,
“如果它没有坏,就不要修理它。”似乎是最后的决定。
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,
"If it ain't broke, don't fix it." seemed to be the final call.