Skip to content

Instantly share code, notes, and snippets.

@BuddyLReno
Created July 11, 2017 12:06
Show Gist options
  • Save BuddyLReno/0ecd0e5cdaefe3e19b88c8ca3a8b146a to your computer and use it in GitHub Desktop.
Save BuddyLReno/0ecd0e5cdaefe3e19b88c8ca3a8b146a to your computer and use it in GitHub Desktop.
Mixin to insert class inside parent selector.
@mixin insertParent($class, $append: false) {
$selString: quote(&);
$parent: str-slice($selString, 0, str-index($selString, " ") - 1);
$minusParent: str-slice($selString, str-index($selString, " ") + 1);
$firstChild: str-slice($minusParent, 0, str-index($minusParent, " ") - 1);
$otherChildren: str-slice($selString, str-index($selString, $firstChild) + str-length($firstChild) + 1);
$selector: unquote("");
@if $append {
$selector: $parent #{$firstChild}#{$class} $otherChildren;
} @else {
$selector: $parent $class $firstChild $otherChildren;
}
@at-root {
#{$selector} {
@content;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment