Skip to content

Instantly share code, notes, and snippets.

@gtwalford
Created August 25, 2016 19:29
Show Gist options
  • Save gtwalford/c2eef9dc78682342b2fab38e67f4f9b1 to your computer and use it in GitHub Desktop.
Save gtwalford/c2eef9dc78682342b2fab38e67f4f9b1 to your computer and use it in GitHub Desktop.
REM Mixin for SCSS
//=== px -> rem USE: @include rem('padding',18px 0 20px 5px);
//=== Thanks to the tons of posts that I put this together with.
@mixin rem($property, $px-values) {
// Convert the baseline into rems
$baseline-rem: $baseline-px / 1rem * 1;
// Print the first line in pixel values
#{$property}: $px-values;
// If there is only one (numeric) value, return the property/value line for it.
@if type-of($px-values) == "number" {
#{$property}: $px-values / $baseline-rem; }
@else {
// Create an empty list that we can dump values into
$rem-values: ();
@each $value in $px-values {
// If the value is zero or not a number, return it
@if $value == 0 or type-of( $value ) != "number" {
$rem-values: append($rem-values, $value); }
@else {
$rem-values: append($rem-values, $value / $baseline-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