--- title: ':first-child' slug: 'Web/CSS/:first-child' tags: - CSS - CSS Pseudoklasse - Layout - Referenz - Web translation_of: 'Web/CSS/:first-child' ---
Die :first-child CSS Pseudoklasse repräsentiert jedes Element, das das erste Kindelement seines Elternelements ist.
element:first-child { Stileigenschaften }
<div> <span>Dieser Text ist grün!</span> <span>Dieser Text nicht. :(</span> </div>
span:first-child {
background-color: lime;
}
... sieht folgendermaßen aus:
{{EmbedLiveSample('Beispiel_1',300,50)}}
<ul> <li>Eintrag 1</li> <li>Eintrag 2</li> <li>Eintrag 3</li> </ul>
li{
color:red;
}
li:first-child{
color:green;
}
... sieht folgendermaßen aus:
{{EmbedLiveSample('Beispiel_2_-_Verwendung_von_UL',300,100)}}
| Spezifikation | Status | Kommentar |
|---|---|---|
| {{SpecName('CSS4 Selectors', '#first-child-pseudo', ':first-child')}} | {{Spec2('CSS4 Selectors')}} | Keine Änderung |
| {{SpecName('CSS3 Selectors', '#first-child-pseudo', ':first-child')}} | {{Spec2('CSS3 Selectors')}} | Ursprüngliche Definition |