Last active
August 29, 2015 14:06
-
-
Save mootari/1edd92ce0933d21c72dd to your computer and use it in GitHub Desktop.
Mixin that allows declarations to be shared between selectors. #sassmeister
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ---- | |
// Sass (v3.3.14) | |
// Compass (v1.0.1) | |
// ---- | |
$registry: (); | |
@mixin common($key, $value) { | |
$prefix: "%common-style"; | |
$index: false; | |
$values: (); | |
$add: false; | |
@if map-has-key($registry, $key) { | |
$values: map-get($registry, $key); | |
$index: index($values, $value); | |
} | |
@if $index == false { | |
$values: append($values, $value); | |
$index: index($values, $value); | |
$add: true; | |
} | |
$placeholder: "#{$prefix}--#{$key}--#{$index}"; | |
@if $add { | |
$registry: map-merge($registry, ($key: $values)); | |
@at-root #{$placeholder} { #{$key}: $value; } | |
} | |
@extend #{$placeholder}; | |
} | |
body { | |
@include common(margin, 12px 5px 2em); | |
@include common(background, red); | |
} | |
html { | |
@include common(background, red); | |
@include common(margin, 12px 10px); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
margin: 12px 5px 2em; | |
} | |
body, html { | |
background: red; | |
} | |
html { | |
margin: 12px 10px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment