Skip to content

Instantly share code, notes, and snippets.

@mcky
Created December 17, 2015 11:27
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 mcky/dbb4b9cbd9201f5ecde6 to your computer and use it in GitHub Desktop.
Save mcky/dbb4b9cbd9201f5ecde6 to your computer and use it in GitHub Desktop.
Specificity override function/mixin
#{specificity('.one', 5)} {
background: purple;
}
@include specificity('.two', 5) {
background: red;
}
/*
* Outputs
* .one.one.one.one.one {
* background: purple; }
*
* .two.two.two.two.two {
* background: red; }
*/
@function specificity($selector, $levels: 2) {
$el: '';
@for $i from 1 through $levels {
$el: append($el, $selector);
}
$el: str-replace(#{$el}, ' ', '');
@return $el;
}
@mixin specificity($selector, $levels: 2) {
#{specificity($selector, $levels)} {
@content;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment