Skip to content

Instantly share code, notes, and snippets.

@brewster1134
Last active February 13, 2016 04:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brewster1134/3106841b311ae8ae5b3e to your computer and use it in GitHub Desktop.
Save brewster1134/3106841b311ae8ae5b3e to your computer and use it in GitHub Desktop.
modify parents from within nested selectors
.vegetables .carrot {
color: orange;
}
.vegetables.out-of-season .carrot {
color: brown;
}
.fruits .apple {
color: red;
}
.fruits .apple.old {
color: brown;
}
// ----
// 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