为什么'foo bar'和'foo> bar'在CSS中具有相同的特异性? [英] Why do 'foo bar' and 'foo > bar' have the same specificity in CSS?

查看:124
本文介绍了为什么'foo bar'和'foo> bar'在CSS中具有相同的特异性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇为什么使用> 或其他组合器不会影响 specificity 的CSS选择器,即为什么 div span em>在某个div中) div>

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.

推荐答案

工作组邮件列表,回来的时候,在此主题

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.

最后,


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.

这篇关于为什么'foo bar'和'foo> bar'在CSS中具有相同的特异性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆