Skip to content

Instantly share code, notes, and snippets.

@mrakowski0
Created April 19, 2013 09:43
Show Gist options
  • Select an option

  • Save mrakowski0/5419272 to your computer and use it in GitHub Desktop.

Select an option

Save mrakowski0/5419272 to your computer and use it in GitHub Desktop.
Mixin that accepts a property and at least one value, then returns it as rem with px fallback.
html {
font-size: 62.5%;
}
.element {
@include rem-fallback(padding, 50, 30);
@include rem-fallback(margin, 120, auto);
}
@mixin rem-fallback($property, $top, $right: $top, $bottom: $top, $left: $right) {
@if $top == $bottom {
@if $top == $right {
#{$property}: $top + px;
#{$property}: ($top / 10) + rem;
}
@else {
@if $right == auto {
#{$property}: $top + px auto;
#{$property}: ($top / 10) + rem auto;
}
@else {
#{$property}: $top + px $right + px;
#{$property}: ($top / 10) + rem ($right / 10) + rem;
}
}
}
@else {
#{$property}: $top + px $right + px $bottom + px $left + px;
#{$property}: ($top / 10) + rem ($right / 10) + rem ($bottom / 10) + rem ($left / 10) + rem;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment