Minh Anh Minh Anh - 2 years ago 61
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.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download