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 - CSS Tutorial
From the course: CSS: Selectors
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,…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
(Locked)
Understanding only selectors, :only-child, :only-of-type2m 22s
-
(Locked)
Understanding first and last selectors, :first-child, :first-of-type, :last-child, :last-of-type3m 7s
-
(Locked)
Understanding nth selectors – :nth-child, :nth-of-type, :nth-last-child, :nth-last-of-type4m 9s
-
(Locked)
:root and :empty4m 27s
-
(Locked)
-
-
-
-
-