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

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 UTC