Skip to content

Instantly share code, notes, and snippets.

@9ete
Last active December 14, 2021 19:23
Show Gist options
  • Save 9ete/941ba60134cb5313a615b08bc8331f4d to your computer and use it in GitHub Desktop.
Save 9ete/941ba60134cb5313a615b08bc8331f4d to your computer and use it in GitHub Desktop.
Dynamic Sass/SCSS Mixin
// Why: reduce lines by grouping related styles (flexbox, background, etc)
// Creates short powerful style mixins see https://gist.github.com/hawkeye126/8328945e412fda9617d9a6a165632dd3
@mixin dynamicMixin($mixin-args: ()){
@each $rule, $value in $mixin-args {
#{$rule}: #{$value};
}
}
// use directly
// @include dynamicMixin(("background-size":"contain", "background-position":"center"));
//
// or extend to mixin
// @mixin set-z-index($position: 1) {
// dynamicMixin(("position":"relative", "z-index":$position))
// }
// elementOne {
// @include set-z-index();
// }
// elementTwo {
// @include set-z-index(2);
// }
// elementThree {
// @include set-z-index(3);
// }
// and so on...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment