Last active
February 13, 2016 04:15
-
-
Save brewster1134/3106841b311ae8ae5b3e to your computer and use it in GitHub Desktop.
modify parents from within nested selectors
This file contains hidden or 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
.vegetables .carrot { | |
color: orange; | |
} | |
.vegetables.out-of-season .carrot { | |
color: brown; | |
} | |
.fruits .apple { | |
color: red; | |
} | |
.fruits .apple.old { | |
color: brown; | |
} |
This file contains hidden or 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
// ---- | |
// Sass (v3.4.21) | |
// Compass (v1.0.3) | |
// ---- | |
// modifies the first selector with custom content | |
// | |
=modifier($modifier, $selector: null) | |
$first-selector: $selector or nth(nth(&, 1), 1) | |
@at-root #{selector-replace(&, $first-selector, "#{$first-selector}#{$modifier}")} | |
@content | |
// by default it modifies the first selector | |
.vegetables | |
.carrot | |
color: orange | |
+modifier('.out-of-season') | |
color: brown | |
// or pass a specific selector | |
.fruits | |
.apple | |
color: red | |
+modifier('.old', '.apple') | |
color: brown |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment