Usage of pseudoclasses

New pseudoclasses are opening new horizons for CSS/HTML coders. Most of the features like first-child, last-child, and nth-child, were added with JavaScript code. For example, using jQuery code, you could get a list element and add specific classes to the first/last/nth element, and then to properly create a selector, you could add a CSS code.

But when it is natively supported by a browser, it is better to use CSS. Let's gather basic knowledge about this feature.

How to use :first-child, :last-child, :nth-child()

A short introduction to these pseudoelements is as follows:

  • :first-child: This points to the element that is the first child of its parent
  • :last-child: This points to the element that is the last child of its parent ...

Get Professional CSS3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.