Skip to content

Instantly share code, notes, and snippets.

@dreamyguy
Created January 20, 2015 21:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dreamyguy/4772b673385f516d1618 to your computer and use it in GitHub Desktop.
Save dreamyguy/4772b673385f516d1618 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// Sass (v3.4.9)
// Compass (v1.0.1)
// ----
// set pixel reference base
$pixelBase: 16 !default;
// strip the unit of measure and return it
@function parseInt($n) {
@return $n / 1;
}
// convert to rem
@function rem-ize($value, $base-value: $pixelBase) {
$value: parseInt($value) / parseInt($base-value) * 1rem;
@if ($value == 0rem) { $value: 0; } // turn 0rem into 0
@return $value;
}
// output values in pixels or in rems
@function unit-calc($values, $base-value: $pixelBase) {
$list: ();
// if '$ie-lt9' is set to true, convert unit to pixel
@if ($ie-lt9) {
@each $i in $values {
$val: parseInt($i);
// if value equals '0' or is not a number, just echo the value (handy for 'auto')
@if ($val == 0 or type-of($val) != "number") {
$list: append($list, $val);
// gimme those pixels!
} @else {
$list: append($list, $val + px);
}
}
// if '$ie-lt9' is set to false, convert unit to rem
} @else {
$max: length($values);
@if $max == 1 {
@return rem-ize(nth($values, 1), $base-value);
}
@for $i from 1 through $max {
$val: parseInt($i);
$list: append($list, rem-ize(nth($values, $val), $base-value));
}
}
@return $list;
}
$ie-lt9: true;
.test {
margin: unit-calc(4 4 8 0);
}
.test {
margin: 4px 4px 8px 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment