Slide 5.21: CSS pseudo-class (cont.)
Slide 5.23: CSS pseudo-class (cont.)
Home

CSS Pseudo-Class (Cont.)


CSS—The :first-child Pseudo-Class
The :first-child pseudo-class matches a specified element that is the first child of another element. Note that for :first-child to work in IE, a <!DOCTYPE> must be declared.
Match the first <p> element
In the example below, the selector matches any <p> element that is the first child of any element:

     


Match the first <i> element in all <p> elements
In the following example, the selector matches the first <i> element in all <p> elements:

     


Demonstration
The following demonstration shows how the script of HTML and CSS is displayed on the Web: