CSS Sass Basics Improve Your Workflow with Sass Write Nested Selectors

Abinet Kenore
Abinet Kenore
10,081 Points

Use the & symbol to create the selector .icn-warning. Set the color of .icn-warning to red.

I tried all the posted Answers to chech after I tried my answers. Those Answer's are not working for me. Here is my trial

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

.button { font-size: 1.5em; }

.icn { font-size: 1.25em;

&-success {
 color: green;

} &-icn-warning { color: red; }

}

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

  .button {
    font-size: 1.5em;
  }

  .icn {
    font-size: 1.25em;

    &-success {
     color: green;
   }
   &-success-warning {
    color: red;}
  }

}

1 Answer

Hey, the below code works fine for this. As you can see you don't need to declare .icn again as you already have it so you just do what you did with the .icn-success class and list it below, you can do this as much as you want to keep the code clean.

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

.icn {
   font-size: 1.25em;
   &-success {
      color: green;
   }
   &-warning {
      color: red;
   }
}