CSS: nth-of-type() selector
Match by Specific Order Rank of Same Tag in Siblings
These let you select the nth occurrence of the tag. (counting only those at the same level children)
tag:first-of-type-
Match tag if it is the first occurrence of tag among siblings.
p:first-of-type { color: red; } this match the aa and cc in the following
<div> <p>aa</p> <p>bb</p> <div> <p class="xx">cc</p> <p class="xx">dd</p> </div> <p>ee</p> </div> tag:last-of-type-
Match tag that is last occurrence of tag among siblings.
tag:nth-of-type(arg)-
equivalent to
:nth-child(arg of tag) tag:nth-last-of-type(arg)-
similar to
:nth-of-type, but counting starting from end.
CSS. Selectors
Selector types
- CSS: types of selectors
- CSS: simple selectors
- CSS: compound selectors
- CSS: complex selector (combinator)
Simple selectors
- CSS: type selector (tag name)
- CSS: universal selector (* any tag)
- CSS: class selector (.x)
- CSS: ID selector (#)
- CSS: attribute selector ([x])
Combinators
- CSS: descendant selector (space)
- CSS: child selector (>)
- CSS: adjacent sibling selector (+)
- CSS: subsequent sibling selector (~)
Selector list
Nesting syntax
Special selector
- CSS: :root selector
- CSS: no child selector
- CSS: first child, sibling rank selector
- CSS: nth-child selector
- CSS: nth-of-type() selector
- CSS: pseudo-class selector (:)
- CSS: pseudo-element selector (::)
- CSS: negation selector (:not)
- CSS: βis any ofβ selector (:is, :where)
- CSS: :has descendant selector