: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