13

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.

8
  • I'm assuming it's just because they are as specific as each other... "a span that is a descendant of a div" and "a span that is a child of a div", rather than something more specific, such as "a span with some class name that is a child of a div". Nov 11, 2011 at 16:18
  • Well you could argue that some span inside a div is not as specific as a span that is an immediate child of a div Nov 11, 2011 at 16:19
  • Yeah, very true. Good question! Nov 11, 2011 at 16:19
  • I can argue that "immediate child" is unnecessarily specific.
    – BoltClock
    Nov 11, 2011 at 16:19
  • 1
    @Josh Stodola: Where does that document (or the latest recommended revision for the matter) explain why combinators don't add to specificity?
    – BoltClock
    Nov 11, 2011 at 16:20

1 Answer 1

9

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.