Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.