Created
November 26, 2012 11:03
-
-
Save LucaRosaldi/4147660 to your computer and use it in GitHub Desktop.
SASS: mixin rem()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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