Skip to content

Instantly share code, notes, and snippets.

@nixstrom
Last active August 29, 2015 14:10
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 nixstrom/23e22814769ec5d8faa4 to your computer and use it in GitHub Desktop.
Save nixstrom/23e22814769ec5d8faa4 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// Sass (v3.4.7)
// Compass (v1.0.1)
// ----
$base-font-size: 16;
//Function to calculate rem value from expected pixel value
@function rem($values...) {
// How many values must we loop through?
$length: length($values);
// Variable to hold our final values
$output: '';
@for $i from 1 through $length {
$value: nth($values, $i);
// If value is 0 or auto, preserve it as is
@if $value == 0 or $value == auto {
$output: #{$output + $value};
}
@else {
// Convert input "base-pixel-value" to corresponding rem value
$value: $value/$base-font-size;
$output: #{$output + $value}rem;
}
// Unless it's the last value, add a whitespace
@if $i < $length {
$output: #{$output + " "};
}
}
@return $output;
}
.foo {
font-size: rem(14);
padding: rem(16, auto, 0, 10);
}
.foo {
font-size: 0.875rem;
padding: 1rem auto 0 0.625rem;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment