01
Selectors
Attribute & Pseudo-class Selectors
CSS3 introduced powerful attribute selectors and pseudo-classes. ^= matches prefix, $= matches suffix, *= matches substring. nth-child enables zebra striping without JavaScript.
css3
/* attribute selectors */
input[type="text"] { border: 1px solid blue; }
a[href^="https"] { color: green; }
a[href$=".pdf"] { color: red; }
a[href*="example"] { font-weight: bold; }
/* pseudo-classes */
a:visited { color: purple; }
li:first-child { font-weight: bold; }
li:nth-child(odd) { background: #f0f0f0; }
input:focus { outline: 2px solid blue; }Structural Pseudo-classes
Structural pseudo-classes select elements by their position in the DOM. :first-child / :last-child target edges. nth-child(an+b) supports formulas: 2n is even, 2n+1 is odd, 3n is every third. :nth-of-type counts only siblings of the same element type. :empty matches elements with no children.
css3