Skip to content

Instantly share code, notes, and snippets.

@johnsylvain
Created January 6, 2018 01:59
Show Gist options
  • Save johnsylvain/47a54f3a9790ee532e0d8554539025a7 to your computer and use it in GitHub Desktop.
Save johnsylvain/47a54f3a9790ee532e0d8554539025a7 to your computer and use it in GitHub Desktop.
BEM SCSS Mixin
/// Block Element
/// @access public
/// @param {String} $element - Element's name
@mixin element($element) {
&__#{$element} {
@content;
}
}
/// Block Modifier
/// @access public
/// @param {String} $modifier - Modifier's name
@mixin modifier($modifier) {
&--#{$modifier} {
@content;
}
}
/// @alias element
@mixin e($element) {
@include element($element) {
@content;
}
}
/// @alias modifier
@mixin m($modifier) {
@include modifier($modifier) {
@content;
}
}
@import 'bem';
.button {
background-color: $bada55;
@include e('text') {
color: white;
font-weight: bold;
}
@include m('red') {
background-color: red;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment