Specificity: Punktesystem für Selektoren
Erscheinungsbild
| Selektor | Beispiel | Punkte |
|---|---|---|
| einfacher Typselektor | p | 1 |
| Klasse | .infobox | 10 |
| Pseudoklasse | :visited | 10 |
| ID | #navibereich | 100 |
Inline-Style mit Attribut style=" " |
style="color: pink;" |
1000 |
Spezifität - Beispiele
| Selektor | Beschreibung | Punkte einzeln | Gesamtpunktzahl |
|---|---|---|---|
body |
Typenselektor | 1 1 | |
h1, h2 |
gruppierte Selektoren | jeder 1 1 | |
a:visited |
Typselektor + Pseudoklasse | 1 + 10 11 | |
.infobox |
ungebundene Klasse | 10 10 | |
p.infobox |
Typselektor + gebundene Klasse | 1 + 10 11 | |
#navibereich |
ID | 100 100 | |
#navibereich a:visited |
ID + Typ + Pseudoklasse | 100 + 1 + 10 111 | |
|
Inline Style | 1000 1000 |
ab CSS 2 zählt ein Matrixsystem:
* {} /* a=0 b=0 c=0 d=0 -> specificity = 0,0,0,0 */
li {} /* a=0 b=0 c=0 d=1 -> specificity = 0,0,0,1 */
li:first-line {} /* a=0 b=0 c=0 d=2 -> specificity = 0,0,0,2 */
ul li {} /* a=0 b=0 c=0 d=2 -> specificity = 0,0,0,2 */
ul ol+li {} /* a=0 b=0 c=0 d=3 -> specificity = 0,0,0,3 */
h1 + *[rel=up]{} /* a=0 b=0 c=1 d=1 -> specificity = 0,0,1,1 */
ul ol li.red {} /* a=0 b=0 c=1 d=3 -> specificity = 0,0,1,3 */
li.red.level {} /* a=0 b=0 c=2 d=1 -> specificity = 0,0,2,1 */
#x34y {} /* a=0 b=1 c=0 d=0 -> specificity = 0,1,0,0 */
style="" /* a=1 b=0 c=0 d=0 -> specificity = 1,0,0,0 */
Siehe: http://www.w3.org/TR/CSS21/cascade.html#specificity
!important hinter einer CSS-Anweisung nimmt die Definition aus dem Punktsystem. Sie zählt auf jeden Fall.