Created
March 16, 2014 11:05
-
-
Save danielguillan/9581556 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
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.3) | |
// Compass (v1.0.0.alpha.18) | |
// ---- | |
// Map storing sizes when the mixin is being called | |
$sizes: ( | |
width : (), | |
height : (), | |
); | |
// A mixin defining both the width and the height | |
// --- | |
// The main problem with this mixin is it doesn't try to | |
// merge selectors when there is either the width or the height | |
// repeated from one call to the other | |
// --- | |
// So here is an over-engineered version which use placeholders | |
// to group selectors when a width or height has already been used | |
// --- | |
// @param: [number] $width: width | |
// @param: [number] $height ($width): height | |
// --- | |
@mixin size($width, $height: $width) { | |
$dimensions: (width $width, height $height); | |
// If the size has not been defined yet | |
// Add the value to the map | |
// And create a placeholder at root | |
@each $dimension, $dimension-value in $dimensions { | |
@if not index(map-get($sizes, $dimension), $dimension-value) { | |
$sizes: map-merge($sizes, ($dimension: append(map-get($sizes, $dimension), $dimension-value))); | |
@at-root %#{$dimension}-#{$dimension-value} { | |
#{$dimension}: $dimension-value; | |
} | |
} | |
// Extend the placeholder | |
@extend %#{$dimension}-#{$dimension-value}; | |
} | |
} | |
.a { | |
@include size(10px, 20px); | |
} | |
.b { | |
@include size(10px, 2em); | |
} | |
.c { | |
@include size(1px, 2em); | |
} |
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
.a, .b { | |
width: 10px; | |
} | |
.a { | |
height: 20px; | |
} | |
.b, .c { | |
height: 2em; | |
} | |
.c { | |
width: 1px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment