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

Cristian Villamarin
Cristian Villamarin
2,310 Points

descendant vs child

what is the difference between a descendant selector and a child selector?

2 Answers

Colin Marshall
Colin Marshall
32,861 Points

Take this example:

<div>
    <ul>
        <li>Item 1</li> 
        <li>Item 2</li>
    </ul>
</div>

The ul is a child of div. The li's are children of the ul, but the li's are not children of the div because they are wrapped inside a set of ul tags, and then wrapped in the div tags.

The ul and the li's are both descendant's of div.

All children of an element are also descendants of that same element, but not all descendants of that element are children of it. Just think of it in terms of an actual family and you should catch on pretty quick.