My original answer regarding :nth-of-type
is simply wrong. Thanks to Paul for pointing this out.
The word "type" there refers only to the "element type" (like div
). It turns out that the selectors div.bar:nth-of-type(2)
and div:nth-of-type(2).bar
mean the same thing. Both select elements that [a] are the second div
of their parent, and [b] have class bar
.
So the only pure CSS solution left that I'm aware of, if you want to select all elements of a certain selector except the first, is the general sibling selector:
.bar ~ .bar
http://www.w3schools.com/cssref/sel_gen_sibling.asp
My original (wrong) answer follows:
With the arrival of CSS3, there is another option. It may not have been available when the question was first asked:
.bar:nth-of-type(2)
http://www.w3schools.com/cssref/sel_nth-of-type.asp
This selects the second element that satisfies the .bar
selector.
If you want the second and last of a specific kind of element (or all of them except the first), the general sibling selector would also work fine:
.bar ~ .bar
http://www.w3schools.com/cssref/sel_gen_sibling.asp
It's shorter. But of course, we don't like to duplicate code, right? :-)