Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Caleb Stevenson
4,005 PointsHow would I efficiently select groups between the first and last elements? (:nth-of-type)
Hey! I was wondering the best method of selecting a group of adjacent elements between the first and last elements. For example: I have ten elements, but I only want to select the second through fourth elements. Is there a way to use the nth-of-type selector for that? If not, what is the best way?
3 Answers
James Barnett
39,199 PointsErik Nemesis
13,356 Pointsnth-of-type(2), nth-of-type(3), nth-of-type(4)
Yes, there's no other ways (AFAIK)
James Barnett
39,199 Points> Yes, there's no other ways (AFAIK)
You have to combine 2 nth-child selectors
Wayne Priestley
19,579 PointsI'm sure you can do this using :nth-child(-2n+4) i think its covered in advanced selectors section of CSS.
(I'm sure someone will correct me if I'm wrong, but I'm pretty sure I'm on the right track)
James Barnett
39,199 PointsThat will only select the 2nd and 4th elements.
Erik Nemesis
13,356 PointsErik Nemesis
13,356 PointsWow, I've never heard of that! Thanks a lot!
James Barnett
39,199 PointsJames Barnett
39,199 PointsGenzo Mallowigi - You can test out your nth-child calculations here: http://codepen.io/jamesbarnett/pen/Fanbj
Caleb Stevenson
4,005 PointsCaleb Stevenson
4,005 PointsThanks!