CSS Master

(Primo) #1
Figure 1.37. Selecting every third element, starting with the fifth

:only-child


The:only-childpseudo-classmatcheselementsiftheyaretheonlychildofanother
element.Belowaretwounorderedlists.Thefirsthasoneitemwhilethesecond
containsthree:


01-selectors/pseudo-class-only-child.html (excerpt)
<ul>
<li>Apple</li>
</ul>

<ul>
<li>Orange</li>
<li>Banana</li>
<li>Raspberry</li>
</ul>

Usingli:only-child{color: #9c27b0;}willselect

  • Apple
  • ,sinceit’s
    theonlychildofourfirstlist.Noneoftheitemsinthesecondlistmatch,however,
    becausetherearethreesiblings.YoucanseewhatthislookslikeinFigure1.38.


    Selectors 55

    Free download pdf