Figure 1.38. Matching elements with li:only-child
:empty
It’salsopossibletoselectelementsthathavenochildrenusingthe:emptypseudo-
class.Nowwhenwesay:empty,wemeanempty.Inorderforanelementtomatch
the:emptypseudo-class,itcan’tcontainanythingelse—notevenwhitespace.In
otherwords,<p></p>willmatch,but<p> </p>willnot.
SometimesWYSIWYG(WhatYouSeeIsWhatYouGet)editorsinsertemptypele-
mentstoyourcontent.Youcoulduse:emptyincombinationwiththe:not()
pseudo-classtoavoidapplyingstylestotheseelements;forexamplep:not(:empty).
Selecting Elements of a Particular Type by their Index
Thepseudo-classesdiscussedintheprevioussectionmatchelementsiftheyoccupy
thegivenpositioninadocumentsubtree.Forinstance,p:nth-last-child(2)selects
everypelementthatisthenext-to-lastelementofitsparent.
Inthissection,we’lldiscusstypedchild-indexedpseudo-classes.Thesepseudo-
classesalsomatchelementsbasedonthevalueoftheirindexes;however,matches
arelimitedtoelementsofaparticulartype.Selectingthefifthpelement,oreven-
indexedh2elements,forexample.
56 CSS Master