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

Estelle Weyl wrote:
> img[src*=photo]:nth-of-type(odd)
> 
> is selecting every odd image in the document, then checking to see if 
> the attribute has the word photo.
> Is that correct according to the spec?

Yes.  "Type" refers to elements name. (Cf. the type selector: "A type
selector is the name of a document language element type written using
the syntax of CSS qualified names. A type selector represents an
instance of the element type in the document tree."[1])

Indeed, the :nth-of-type(an+b) pseudo-class notation "represents an
element that has an+b-1 siblings with the same expanded element name
before it in the document tree, for any zero or positive integer value
of n, and has a parent element."[2]


> My assumption is that :nth-of-type, being a pseudo-class, has greater 
> specificity than the attribute selector, but then shouldn't the :not 
> pseudo have equal weight? I reversed the order, nothing seems to work.

"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.


[1] http://www.w3.org/TR/css3-selectors/#type-selectors
[2] http://www.w3.org/TR/css3-selectors/#nth-of-type-pseudo
[3] http://www.w3.org/TR/css3-selectors/#specificity
[4] http://www.w3.org/TR/css3-selectors/#negation

Cheers,
Anton Prowse
http://dev.moonhenge.net

Received on Sunday, 4 July 2010 08:26:07 UTC