Created
December 5, 2017 09:27
-
-
Save brookjordan/1d4ea60f37231c093fa5e09919d34cc9 to your computer and use it in GitHub Desktop.
In order to just add an element to a selector in SCSS is infuriatingly difficult. This attempts to ease the pain.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Usage: | |
// | |
// .my-class { | |
// // other styles… | |
// | |
// @include add-element(a) { | |
// color: blue; | |
// } | |
// | |
// // other styles… | |
// } | |
// | |
// As these either don't work, or don't have the desired effect: | |
// | |
// .my-class { | |
// // other styles… | |
// | |
// a& { // "&" may only be used at the beginning of a compound selector. | |
// color: blue; | |
// } | |
// | |
// a#{&} { // outputs: ".my-class a.my-class" | |
// color: blue; | |
// } | |
// | |
// // other styles… | |
// } | |
// | |
@mixin add-element($element) { | |
@at-root #{$element}#{&} { | |
@content; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment