CSS Selectors Basic Combinators Pseudo
Ringkasan
Selector menentukan elemen mana yang kena style. Menguasai selector = tulis CSS lebih sedikit & tepat sasaran.
Konsep Dasar
- Type:
p,h1— tag. - Class:
.btn— bisa dipakai banyak. - ID:
#header— satu, spesifik tinggi (hindari untuk style umum). - Combinator:
(descendant),>(child),+(sibling adj),~(sibling general). - Pseudo-class:
:hover,:focus,:nth-child(),:not(),:first-child. - Attribute:
[type="text"],[href^="https"].
Cara Kerja / Struktur
.card > .title { font-weight: 700; }
li:nth-child(2n) { background: #f3f3f3