Minh Anh Minh Anh - 10 months ago 27
CSS Question

How to style for first-child?

For example, I have HTML like :

<div class='page'>

How can I style for first child a

I used like this :
.page a:first-child {color:red}

but it doesn't run.


Use first-of-type instead of first-child

.page a:first-of-type{

The :first-of-type CSS pseudo-class represents the first sibling of its type in the list of children of its parent element.

Taken from MDN Documentation. You can find more details & examples here.

Explanation : :first-child not working as expected