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 trialNa Da
5,041 PointsAre child selectors expensive?
Just wanted to know the best practices involving child selectors.
1 Answer
Jacob Moyle
6,150 PointsHello Naomi,
Short answer: They're in the middle.
"Selectors have an inherent efficiency, and to quote Steve Souders, the order of more to less efficient CSS selectors goes thus:
- ID, e.g. #header
- Class, e.g. .promo
- Type, e.g. div
- Adjacent sibling, e.g. h2 + p
- Child, e.g. li > ul
- Descendant, e.g. ul a
- Universal, i.e. *
- Attribute, e.g. [type="text"]
- Pseudo-classes/-elements, e.g. a:hover
Quoted from Even Faster Websites by Steve Souders"
If you are looking for a more in depth article, I would recommend this one (which is where I pulled that block of text from). I hope this is helpful!