Skip to content

Instantly share code, notes, and snippets.

@lmartins
Last active August 29, 2015 14:25
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 lmartins/be61e48a9354e21171af to your computer and use it in GitHub Desktop.
Save lmartins/be61e48a9354e21171af to your computer and use it in GitHub Desktop.
Mixins for BEM style selectors.
// ----
// libsass (v3.2.5)
// ----
// BEM Mixins for SASS
// http://www.sitepoint.com/structuring-css-class-selectors-with-sass/
@mixin new($block) {
@at-root .#{$block} {
@content;
}
}
@mixin is($element) {
.is-#{$element} & {
@content;
}
}
@mixin has($element) {
&__#{$element} {
@content;
}
}
@mixin when($modifier) {
&--#{$modifier} {
@content;
}
}
@mixin when-inside($selector) {
#{$selector} & {
@content;
}
}
.media {
border: 1px solid red;
@include has("image") {
border: 1px solid green;
@include when('full') {
content: "full";
}
@include is('modifier') {
content: "modifier";
}
}
@include when-inside('.page-header') {
content: "new"
}
@include when('new') {
content: "new"
}
}
.media {
border: 1px solid red;
}
.media__image {
border: 1px solid green;
}
.media__image--full {
content: "full";
}
.is-modifier .media__image {
content: "modifier";
}
.page-header .media {
content: "new";
}
.media--new {
content: "new";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment