Skip to content

Instantly share code, notes, and snippets.

@oranj
Created December 3, 2015 20:40
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 oranj/f238c44f15cd71de8765 to your computer and use it in GitHub Desktop.
Save oranj/f238c44f15cd71de8765 to your computer and use it in GitHub Desktop.
BEM SASS Mixins
// BEM mixins (Block, Element, Modifier)
//
// Just google if you're confused.
@mixin block($name) {
@at-root .#{$name} {
@content;
}
}
@mixin element($names...) {
$selector: "";
$i: 1;
@each $name in $names {
@if ($i != 1) {
$selector: ", #{$selector}";
}
$selector: "#{&}__#{$name} #{$selector}";
$i: $i + 1;
}
@at-root #{$selector} {
@content;
}
}
@mixin modifier($names...) {
$selector: "";
$i: 1;
@each $name in $names {
@if ($i != 1) {
$selector: ", #{$selector}";
}
$selector: "#{&}--#{$name} #{$selector}";
$i: $i + 1;
}
@at-root #{$selector} {
@content;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment