Created
May 17, 2012 17:41
-
-
Save pfulton/2720471 to your computer and use it in GitHub Desktop.
Compass "scale" mixin for calculating ems
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
// for the life of me, I can't track down the original place where I found this. | |
// syntax for scale mixin is like this | |
// property, sizes in px, context | |
//@include scale(padding, (16, 14, 12, 9), 20); | |
// 16px is default context size | |
@mixin scale($props, $sizes, $base: 16) { | |
$values: (); | |
$sublists: false; | |
@each $s in $sizes { | |
// unwrap lists for values that have multiple list of values such as text-shadow | |
@if type-of($s) == list { | |
$sublists: true; | |
$vv: (); | |
@each $ss in $s { | |
$vv: append($vv, if(type-of($ss) == number, #{$ss / $base}em, $ss)); | |
} | |
$values: append($values, join((), $vv)); | |
} @else { | |
$values: append($values, if(type-of($s) == number, #{$s / $base}em, $s)); | |
// $values: append($values, #{$s}px); | |
} | |
} | |
$value: join((), $values, if($sublists, comma, space)); | |
@each $prop in $props { #{$prop}: $value } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment