first-child and nth-child selectors : Styling multiple Elements with same class – CSS

first-child  – This selector selects first child of its parent.

To color first one of elements with the same class,we use first-child selector.Consider below example with multiple divs(.box)  inside parent div(.container).To change the style of first div


nth-child – This selector selects nth child of its parent.

We can achieve the above result using nth-child selector .The number in the bracket indicates the order of the child


No Comments

Leave a Reply

Your email address will not be published. Required fields are marked *