W3C home > Mailing lists > Public > www-style@w3.org > July 2010

Re: Specificity: nth-of-type versus attribute selector?

From: L. David Baron <dbaron@dbaron.org>
Date: Sun, 4 Jul 2010 09:09:50 -0700
To: www-style@w3.org
Cc: Estelle Weyl <estelle@weyl.org>
Message-ID: <20100704160950.GA11937@pickering.dbaron.org>
On Sunday 2010-07-04 10:24 +0200, Anton Prowse wrote:
> "Specificity" isn't the right term here (it has another meaning in CSS
> Selectors [3]) but I understand what you're asking.  However, there is
> no universal common behaviour of pseudo-classes as regards their
> interaction with other parts of the sequence of simple selectors to
> which they belong.
> 
> Hence we must turn to the definition of the :not pseudo-class to
> discover its behaviour:
> 
> "The negation pseudo-class, :not(X), is a functional notation taking a
> simple selector (excluding the negation pseudo-class itself) as an
> argument. It represents an element that is not represented by its
> argument."[4]
> 
> So, in the sense you mean, the :not pseudo-class does behave differently
> from the :nth-of-type pseudo-class in that the whole of the simple
> selector argument is taken into consideration.

I think this is a confusing way to describe things.  I think it's
clearer to simply say that the parts of the simple selector are
independent of each other, and then the results are combined.  Thus:

  :nth-of-type(5) selects any p element that is the fifth p element
  within its parent, any div element that is the fifth div element
  within its parent, any i element that is the fifth i element
  within its parent, etc.

  p selects any p element.

  p:nth-of-type(5) selects the intersection of those two sets, which
  is any p element that is the fifth p element within its parent.

Thus, if you add attribute selectors to the same simple selector,
you're not changing what :nth-of-type() means, you're just
intersecting the result with an additional restriction.

-David

-- 
L. David Baron                                 http://dbaron.org/
Mozilla Corporation                       http://www.mozilla.com/
Received on Sunday, 4 July 2010 16:10:19 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 17:20:29 GMT