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 Sass Basics Write Smart and Efficient CSS with Sass Nesting Media Queries

Joe W
seal-mask
.a{fill-rule:evenodd;}techdegree
Joe W
Front End Web Development Techdegree Student 5,623 Points

Advantages to nesting media queries in sass?

Can someone explain the advantage to nesting media queries like Guil does? Sure, it looks easier for a developer to read, but it seems to be more typing. Also, the output looks far more messy.

2 Answers

Jamie Reardon
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jamie Reardon
Treehouse Project Reviewer

He is showing you how you can nest rules within rules. Why do this? Because you type far less repetition in your code by not having to repeat typing the same class, thus using one rule for the selector.

So it isn't more typing like you said, imagine saving the typing for longer selector names than the example in the video.

The output isn't going to matter, when you are going to compile/code it though sass anyway. Furthermore, you want to limit the level you nest selectors (no more than 2 levels if that).

mdmaleksharafali
mdmaleksharafali
2,392 Points

The correct answer should be: Nesting keeps media queries local to the component and the original styles we are modifying.