为什么“foo bar”会这样?和'foo>酒吧' CSS 有同样的特殊性吗?

发布于 2024-12-14 20:51:27 字数 299 浏览 2 评论 0原文

我很好奇为什么使用 > 或其他组合器不会影响 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

断念 2024-12-21 20:51:27

这实际上已经在工作组邮件列表中提出了,早在 此线程

它基本上可以归结为,是的,直观上带有组合器的选择器看起来更具体,但是从当前算法扩展而来的算法,考虑到这一点变得比现在使用的“简单”三元组复杂得多,这对于人们就这样。

最后,

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.

“如果它没有坏,就不要修理它。”似乎是最后的决定。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文