Skip to content

Instantly share code, notes, and snippets.

@wfendler
Created April 8, 2014 17:01
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 wfendler/10156395 to your computer and use it in GitHub Desktop.
Save wfendler/10156395 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// Sass (v3.3.4)
// Compass (v1.0.0.alpha.18)
// ----
// Assumptions
$base-font-size: 12px; // mobile
$base-font-size--large: 16px; // desktop
$line-height-ratio: 1.5;
$legacy-ie: true;
@mixin rem($property, $rem_values) {
// LEGACY IE PX FALLBACK CALCULATION
// based off of "desktop" font size
@if $legacy-ie == true {
// If there's only one numeric value:
@if type-of($rem_values) == 'number' {
// if it's zero, no calculation or unit necessary
@if $rem_values == 0 {
#{$property}: $rem-values;
} @else {
#{$property}: $rem-values * $base-font-size--large;
}
}
// If there is more than one value, create a list and perform equations on each value
@else {
// Create an empty list that we can dump values into
$px_values: ();
@each $value in $rem_values {
// if it's zero, no calculation or unit necessary
@if $value == 0 {
$px_values: append($px_values, $value);
} @else {
$px_values: append($px_values, ($value * $base-font-size--large));
}
}
// Return the property and its list of converted values
#{$property}: $px_values;
}
}
@else {
$rem_values_with_unit: ();
@each $value in $rem_values {
$rem_values_with_unit: append($rem_values_with_unit, $value + rem);
}
#{$property}: $rem_values_with_unit;
}
}
.heading {
@include rem(margin-bottom, 1 0);
}
.heading {
margin-bottom: 16px 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment