CSS/Selectors/pseudo-classes/:only-of-type

From Web Education Community Group
< CSS‎ | Selectors
Revision as of 19:01, 21 November 2011 by Rworth (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Pseudo-class :only-of-type

The :only-of-type pseudo-class represents an element that has a parent element and whose parent element has no other element children with the same expanded element name. Same as :first-of-type:last-of-type or :nth-of-type(1):nth-last-of-type(1), but with a lower specificity.

Syntax

selector:only-of-type{ properties }


Example

[style.css]

 h1:only-of-type{
   background-color: yellow;
 }


[index.html]

<body>
  <h1>Only-child example</h1>
  <p>This is a paragraph.</p>
  <p>This is a paragraph.</p>
</body>

Css3 selectors only-of-type.png

CSS defines the :only-of-type pseudo-class selector in 6.6.5.11. :only-of-type pseudo-class.