CSS Sass Basics Improve Your Workflow with Sass Write Nested Selectors

Nest a .button selector inside the .banner rule. Set the font-size of .button to 1.5em

Nest a .button selector inside the .banner rule. Set the font-size of .button to 1.5em. need help

style.scss
.banner {
  padding: 1em;
  background-color: lightgrey;
}
.button{
font-size:1.5em;
}

1 Answer

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 87,411 Points

Hi Carol,

So at the moment what you're doing is writing 2 independent styles in the same way you would a standard CSS file. So if you were to compile that with CSS it would give you exactly the same output.

If you cut and paste the banner style rule and put it before the closing curly brace that should give you different CSS output. That's what nesting is, a selector that goes inside another selector.

hie Jonathan if u can please write the code down for me i have tried the way u said still getting wrong

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 87,411 Points

Okay, before I do that let's just go over again what we talked about with nesting.

Nesting doesn't mean anything to CSS. It's just a way of organising code in SASS so it can output CSS in a way you normally would see in a CSS file.

.banner {
  padding: 1em;
  background-color: lightgrey;

   .button{
      font-size:1.5em;
   }

}

If you organise the code as seen above you'll see what I mean. See how the .banner style contains yet another style rule?

If you tried something like this and it didn't work my guess is you tried a slightly different property and/or value to the one the challenge was expecting. :-)