Skip to content

Instantly share code, notes, and snippets.

@LucaRosaldi
Created November 26, 2012 11:03
Show Gist options
  • Save LucaRosaldi/4147660 to your computer and use it in GitHub Desktop.
Save LucaRosaldi/4147660 to your computer and use it in GitHub Desktop.
SASS: mixin rem()
// Thanks to Maykel Loomans
// http://miekd.com/articles/sizing-type-leading-and-vertical-dimensions-with-rem-units/
$baseFontSize: 16px;
@mixin rem($property, $px_values) {
$baseline_rem: ($baseFontSize / 1rem);
#{$property}: $px_values;
@if type-of($px_values) == 'number' {
#{$property}: $px_values / $baseline_rem;
}
@else {
$rem_values: ();
@each $value in $px_values {
@if $value == 0 {
$rem_values: append($rem_values, $value);
} @else {
$rem_values: append($rem_values, ($value / $baseline_rem) );
}
}
#{$property}: $rem_values;
}
}
h1 {
@include rem(font-size, 25px);
@include rem(margin, 0 0 12px);
}
// Translates into:
h1 {
font-size: 25px;
font-size: 1.5625rem;
margin: 0 0 12px;
margin: 0 0 .75rem;
}
// Media Query to scale up/down the font size:
@media screen and (max-width: 600px) {
html {
font-size: 50%;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment