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

Steven Barrett
Steven Barrett
1,382 Points

Why not place the targeted element inside the brackets?

For example why would this video use something like

header p { color: yellow; }

Rather than

header {

p { color: yellow; }

}

Surely the latter does the same thing? And allows for multiple elements to be targeted without keep declaring header everytime?

1 Answer

Steven Parker
Steven Parker
231,248 Points

You can't nest rules in ordinary CSS, it is a syntax error and causes the entire rule to be ignored. It could certainly be handy, and is in fact implemented in popular pre-processors (like SCSS and Sass).

But for normal CSS, both tags are necessary to create a descendant selector.