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 CSS Basics (2014) Basic Selectors Descendant Selectors

Elizabeth Leon-Guerrero
seal-mask
.a{fill-rule:evenodd;}techdegree
Elizabeth Leon-Guerrero
Front End Web Development Techdegree Student 1,680 Points

What are the benefits of using Descendant Selectors?

Hi! At the end of the video, Guil mentions that using descendant selectors make the css rules less reusable and that we're better off using a class for the element.

So is there any particular benefit to using a descendant selector? and what are some situations in which a Descendant Selector would be more handy?

1 Answer

Steven Parker
Steven Parker
231,269 Points

They are always "handy" because you wouldn't need to modify the HTML. But since they depend on one thing being inside another, a more direct selection method (like giving things the same class) makes the rule more "reusable".

The situation would determine how much of a drawback this might be, as re-usability might not even be a factor in some cases.

Elizabeth Leon-Guerrero
seal-mask
.a{fill-rule:evenodd;}techdegree
Elizabeth Leon-Guerrero
Front End Web Development Techdegree Student 1,680 Points

Ahh, I see - so, for some projects it's not necessary for a rule to be reusable, in which case it's a bit quicker and just as effective to target the html with a descendent selector instead of assigning a class or id... okay, I get it now! thanks!