Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
- :first-child and :last-child 4:15
- :first-child and :last-child Challenge 2 objectives
- :only-child and :empty 4:58
- Substring Matching Attribute Selectors - "Begins With" and "Ends With" 8:19
- Substring Matching Attribute Selectors - "Contains" 6:44
- Substring Matching Attribute Selectors Challenge 3 objectives
- Element States Pseudo-Classes 6:20
- Structural and Element States Pseudo-Classes Review 5 questions

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
In this video, we'll learn how to target first and last-child elements with the :first-child and :last-child structural pseudo-classes.
Quick Reference
Using :first-child and :last-child
To target the first child div
element inside a parent, we can write:
div:first-child {
margin-left: 0;
}
To target the last li
element in a list, we can write:
li:last-child {
color: tomato;
}
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
Silvia Ramos
Front End Web Development Techdegree Graduate 18,318 Points7 Answers
-
professionalb
Full Stack JavaScript Techdegree Student 5,082 Points1 Answer
-
PLUS
Miriam Allman
Courses Plus Student 1,761 Points8 Answers
-
Ary de Oliveira
28,298 Points1 Answer
-
Oliver Sewell
16,425 Points5 Answers
-
MOD
Jason Anders
Treehouse Moderator 145,860 Points1 Answer
-
PLUS
Jay Valentine
Courses Plus Student 4,389 Points3 Answers
-
Michael Stickley
3,958 Points2 Answers
View all discussions for this video
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up