CSS Tips | :first-child

Post

Using the CSS pseudo-class :first-child allows you to style any thing that is the "first child" of another element. One case that this may be helpful is when you want a different style for the first li element in your list. i.e. additional margin, color, etc. This would be done like this.

ul li:first-child {
margin-top: 20px;
color: #000000;
}

Support for this pseudo-class is limited to Firefox, Safari and versions of Internet Explored later than IE6.

Comments

Leave a comment

October 2026
Sun
Mon
Tue
Wed
Thu
Fri
Sat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Share