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

is there a difference between div p and div > p?

for example these basically do the same thing right? Im a bit confused as to why the first exists in the CSS language

div > p {
    background-color: yellow;
}

vs

div p {
    background-color: yellow;
}

1 Answer

Here's what I got:

[div > p] selects only the p that are children of the div. So if you had a div with lists or whatever inside that had their own p, their properties would not be affected by this selector.

[div p] selects all descendant p in the div. So any p that is inside, or descendant, of a div would be affected.

This probably isn't the best example of the difference between the child selector (>) and the descendant selector, but I hope this helps!

yeah that makes sense thanks man