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

CSS

Kailash Seshadri
Kailash Seshadri
3,087 Points

why use :nth-child when we can use :nth-of-type every time, as its more specific?

Why do we use :nth-child when we have :nth-of-type and be more specific? it seems pretty useless compared to the :nth-of-type pseudo class.....

Thanks for the help!!

1 Answer

Jackie Keiser
Jackie Keiser
9,833 Points

:nth-of-type may be more specific but there might be a situation where you don't know what type of element is going to be used and so :nth-child would be more appropriate. This might be the case if you're using the same style for different types of elements or if you're working with user generated content.