:only-of-type

:only-of-type – pseudo-class | Selectors Level 3

The :only-of-type matches element that is only child of its parent element of given type.

Syntax

element:only-of-type{
    style properties
}

Example

The HTML code

<div>
    <ul>
        <li>1</li>
        <li>2</li>
    </ul>
    <p>Paragraph</p>
    <div>I am a div.</div>
</div>
p:only-of-type{
    background:#FFB7C5;
}

The paragraph p is selected because it is the only one in the parent element.

  • 1
  • 2

Paragraph

I am a div.

Related

Resources

Posted in CSS

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.