Skip to content

Instantly share code, notes, and snippets.

@pfulton
Created May 17, 2012 17:41

Revisions

  1. pfulton created this gist May 17, 2012.
    27 changes: 27 additions & 0 deletions scale.scss
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    // 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 }
    }