The only-child pseudo-class

The only-child pseudo-class selects an element that is the only child of its parent.

Syntax

cssselector:only-child {
  
}

Example

In this example, we will make li red if it is the only child of the parent ul:

html<ul>
  <li>list item</li>
</ul>

<ul>
  <li>list item</li>
  <li>list item</li>
  <li>list item</li>
</ul>
cssli:only-child {
  color: red;
}

ul {
  margin-bottom: 10px;
}

Результат: