Created
May 12, 2012 19:55
-
-
Save kara-ryli/2668582 to your computer and use it in GitHub Desktop.
Easy brower-compatible rem units with SCSS
This file contains hidden or 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
/* Note: this method disables user font scaling via browser preferences. | |
It's up to you whether this is a good thing. In this case, browsers | |
that don't support rem get the default (pixel) value, and don't get | |
the fancy scaling. | |
*/ | |
$rem_size: 10; | |
$rem_px: #{$rem_size}px; | |
@mixin rem($property, $value) { | |
#{$property}: $value * $rem_size; | |
#{$property}: #{$value}rem; | |
} | |
/* sets <html /> font size to your rem unit */ | |
html { font-size: $rem_px; } | |
/* changes font scale based for a larger page width */ | |
@media only screen and (min-width: 480px) { | |
html { font-size: 20px;} | |
} | |
/* sets the <body /> font size to 16px (the de-facto browser default. */ | |
body { font-size: 1600%/$rem_size;} | |
/* sets the element's font-size and border-width to rem values, | |
defaulting to pixels. | |
*/ | |
.element-somewhere { | |
@include rem(font-size, 2.2); | |
@include rem(border-width, 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
REM unit support is in most browsers.