Skip to content

Instantly share code, notes, and snippets.

@dani-z
Created November 5, 2013 09:40
Show Gist options
  • Save dani-z/7316393 to your computer and use it in GitHub Desktop.
Save dani-z/7316393 to your computer and use it in GitHub Desktop.
// ----
// Sass (v3.3.0.rc.1)
// Compass (v0.13.alpha.10)
// ----
$em-base: 16px;
@function strip-unit($num) {
@return $num / ($num * 0 + 1);
}
@function convert-to-rem($value, $base-value: $em-base) {
$value: strip-unit($value) / strip-unit($base-value) * 1rem;
@if ($value == 0rem) { $value: 0; } // Turn 0em into 0
@return $value;
}
@function print-px($values) {
$max: length($values);
@if $max == 1 { @return strip-unit(nth($values, 1)) + px; }
$pxValues: ();
@for $i from 1 through $max {
$pxValues: append($pxValues, strip-unit(nth($values, $i)) + px);
}
@return $pxValues;
}
@function rem-calc($values, $base-value: $em-base) {
$max: length($values);
@if $max == 1 { @return convert-to-em(nth($values, 1), $base-value); }
$remValues: ();
@for $i from 1 through $max {
$remValues: append($remValues, convert-to-rem(nth($values, $i), $base-value));
}
@return $remValues;
}
@mixin prop($prop, $values) {
#{$prop}: print-px($values);
#{$prop}: rem-calc($values);
}
.test {
@include prop(margin, 10 16);
}
.test {
margin: 10px 16px;
margin: 0.625rem 1rem;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment