Skip to content

Instantly share code, notes, and snippets.

@mattjburrows
Created October 10, 2014 10:12
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 mattjburrows/d02d963bc2f8c9fd04c1 to your computer and use it in GitHub Desktop.
Save mattjburrows/d02d963bc2f8c9fd04c1 to your computer and use it in GitHub Desktop.
Rem mixin
@mixin rem($property, $px, $base: 16px) {
// Convert the baseline into rems
$rem: $base / 1rem;
// Print the first line in pixel values
#{$property}: $px;
// If there is only one (numeric) value, return the property/value line for it.
@if type-of($px) == "number" {
#{$property}: $px / $rem;
}
@else {
// Create an empty list that we can dump values into
$rem-values: unquote("");
@each $value in $px {
// If the value is zero, return 0
@if $value == 0 {
$rem-values: append($rem-values, $value);
}
@else {
$rem-values: append($rem-values, $value / $rem);
}
}
// Return the property and its list of converted values
#{$property}: $rem-values;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment