Structural Pseudo-classes
Structural pseudo-classes select elements based on their position in the document.
:first-child and :last-child
Select the first or last child element:
Loading Selector Playground...
Try:
li:first-child- first list itemli:last-child- last list item
:first-of-type and :last-of-type
Select first/last of a specific element type:
Loading Selector Playground...
p:first-of-type- first paragraphp:last-of-type- last paragraph:first-of-typeignores other element types
Styling Lists
Loading CSS Playground...
:only-child
Selects an element that is the only child:
Loading Selector Playground...
:empty
Selects elements with no children:
Loading Selector Playground...
Styling Empty States
Loading CSS Playground...
:not() Negation
Select elements that don't match a selector:
Loading Selector Playground...
Practical :not() Usage
Loading CSS Playground...
Exercise: Style First Item
Style the first list item differently:
Loading CSS Exercise...

