From the course: CSS: Selectors

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Understanding nth selectors – :nth-child, :nth-of-type, :nth-last-child, :nth-last-of-type

Understanding nth selectors – :nth-child, :nth-of-type, :nth-last-child, :nth-last-of-type - CSS Tutorial

From the course: CSS: Selectors

Start my 1-month free trial

Understanding nth selectors – :nth-child, :nth-of-type, :nth-last-child, :nth-last-of-type

- [Instructor] In the last two videos, you've learned to select the first, last or only child, and the first, last or only of a type. I'm sure you're shocked, shocked, to know that you can also select any other item you wish. For example, you want every third item? Every fifth item, starting with the second? These can all be coded with the nth selectors, including nth-child, nth-of-type, nth-last-child and nth-last-of-type. Let's just focus on nth-child for the moment, because once you understand how one of these nth selectors work, you'll pretty quickly get them all. First of all, an nth-child selector must take an argument to describe what number n is equal to. Let's start with the easy one, which is with key words. So, if I simply say li:nth-child even, just like that, and say color: orange. What I will get is the even numbered list items will wind up being orange. And fortunately, even is defined in human terms, so it is in fact numbers two, four and six, not in engineering terms,…

Contents