问题
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.
回答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.
来源:https://stackoverflow.com/questions/8096829/why-do-foo-bar-and-foo-bar-have-the-same-specificity-in-css