Skip to content

Instantly share code, notes, and snippets.

@jensgro
Created May 28, 2014 08:13
Show Gist options
  • Select an option

  • Save jensgro/8158bf0170bee06ad727 to your computer and use it in GitHub Desktop.

Select an option

Save jensgro/8158bf0170bee06ad727 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// Sass (v3.2.19)
// Compass (v0.12.6)
// ----
@function strip-unit($value) {
@return $value / ($value * 0 + 1);
}
// ===============================================
// http://css-tricks.com/snippets/css/less-mixin-for-rem-font-sizing/
@mixin rem($property, $values...) {
$max: length($values);
$pxValues: '';
$remValues: '';
@if $property == fz {
$property: font-size;
} @else if $property == m {
$property: margin;
} @else if $property == mt {
$property: margin-top;
} @else if $property == mr {
$property: margin-right;
} @else if $property == mb {
$property: margin-bottom;
} @else if $property == ml {
$property: margin-left;
} @else if $property == p {
$property: padding;
} @else if $property == pt {
$property: padding-top;
} @else if $property == pr {
$property: padding-right;
} @else if $property == pb {
$property: padding-bottom;
} @else if $property == pl {
$property: padding-left;
}
@for $i from 1 through $max {
$value: strip-unit(nth($values, $i));
$pxValues: #{$pxValues + $value}px;
@if $i < $max {
$pxValues: #{$pxValues + " "};
}
}
@for $i from 1 through $max {
$value: strip-unit(nth($values, $i));
$remValues: #{$remValues + $value/16}rem;
@if $i < $max {
$remValues: #{$remValues + " "};
}
}
#{$property}: $pxValues;
#{$property}: $remValues;
}
.test {
@include rem(p,30,10,10);
@include rem(fz,40);
}
.test-mt {
@include rem(mt,20);
}
.test-m {
@include rem(m,30,10,10);
}
.test {
padding: 30px 10px 10px;
padding: 1.875rem 0.625rem 0.625rem;
font-size: 40px;
font-size: 2.5rem;
}
.test-mt {
margin-top: 20px;
margin-top: 1.25rem;
}
.test-m {
margin: 30px 10px 10px;
margin: 1.875rem 0.625rem 0.625rem;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment