Skip to content

Instantly share code, notes, and snippets.

@onishiweb
Created October 16, 2013 17:58
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 onishiweb/7012088 to your computer and use it in GitHub Desktop.
Save onishiweb/7012088 to your computer and use it in GitHub Desktop.
Rem Sass mixin (originally by @BPScott)
// Rems with pixel fallback for any property
// @author @BPScott (https://github.com/BPScott/bpscott.github.io/blob/develop/source/stylesheets/vendor/_rem.scss)
@mixin rem($property, $px-values, $baseline-px: $base-font-size) {
// Convert the baseline into rems
$baseline-rem: $baseline-px / 1rem;
// Create an empty list that we can dump values into
$rem-values: ();
@each $value in $px-values {
// If the value is zero, return 0
$rem-values: append($rem-values, if($value == 0, $value, $value / $baseline-rem));
}
// Output the property's px and rem values
#{$property}: $px-values;
#{$property}: $rem-values;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment