Skip to content

Instantly share code, notes, and snippets.

@EdPoole
Created May 16, 2013 18:02
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EdPoole/5593712 to your computer and use it in GitHub Desktop.
Save EdPoole/5593712 to your computer and use it in GitHub Desktop.
Converts pixel values to rem values with pixel fallbacks.
$baseline_px: 16px;
@mixin rem($property, $px_values) {
$baseline_rem: ($baseline_px / 1rem);
#{$property}: $px_values;
@if type-of($px_values) == 'number' {
#{$property}: $px_values / $baseline_rem;
} @else {
$rem_values: ();
@each $value in $px_values {
@if $value == 0 {
$rem_values: append($rem_values, $value);
} @else {
$rem_values: append($rem_values, ($value / $baseline_rem) );
}
}
#{$property}: $rem_values;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment