Skip to content

Instantly share code, notes, and snippets.

@scheibome
Last active June 11, 2019 10:34
Show Gist options
  • Save scheibome/d9787b0834b3ed5ca5972ce09668d8fe to your computer and use it in GitHub Desktop.
Save scheibome/d9787b0834b3ed5ca5972ce09668d8fe to your computer and use it in GitHub Desktop.
How can I write this in #SCSS without writing the >li again? I don't have a clue
// How can I write this in #SCSS without writing the > li for message--error again?
// like .message.message--error > li
.message {
> li {
background-color: green;
}
&.message--error {
> li {
background-color: red;
}
}
}
@gisu
Copy link

gisu commented Jun 11, 2019

.message {
  > li {
    background-color: green;
    .message--error & {
      background-color: red;
    }
  }
}

@scheibome
Copy link
Author

.message {
  > li {
    background-color: green;
    .message--error & {
      background-color: red;
    }
  }
}

Unfortunately, this is not what I want.

@scheibome
Copy link
Author

scheibome commented Jun 11, 2019

Find a solution:

//.message > li {
//  background-color: green;
//}
//.message--error.message > li {
//  background-color: red;
//}


.message {
  > li {
    
    @at-root & {
      background-color: green;
    }
    
    @at-root .message--error#{&} {
      background-color: red;
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment