Skip to content

Instantly share code, notes, and snippets.

@kara-ryli
Created May 12, 2012 19:55
Show Gist options
  • Save kara-ryli/2668582 to your computer and use it in GitHub Desktop.
Save kara-ryli/2668582 to your computer and use it in GitHub Desktop.
Easy brower-compatible rem units with SCSS
/* 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);
}
@kara-ryli
Copy link
Author

REM unit support is in most browsers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment