Skip to content

Instantly share code, notes, and snippets.

@atelierbram
Last active January 2, 2016 23:39
Show Gist options
  • Save atelierbram/8377708 to your computer and use it in GitHub Desktop.
Save atelierbram/8377708 to your computer and use it in GitHub Desktop.
Rems fallbacks and support
/* the font-size mixin */
/* example of usage */
.prose p {
font-size: 14px;
font-size: 0.875rem;
}
// ----
// Sass (v3.3.0.rc.2)
// Compass (v1.0.0.alpha.17)
// ----
// http://alwaystwisted.com/post.php?s=2014-01-01-rems-fallbacks-and-support
$doc-font-size: 16;
/* the font-size mixin */
@mixin font-size-1($size) {
font-size: 0px + $size;
font-size: 0rem + $size / $doc-font-size;
}
/* example of usage */
p {
@include font-size-1(14);
}
/*
* http://zerosixthree.se/8-sass-mixins-you-must-have-in-your-toolbox/
* or with an extra function to make it a bit cleaner by seperating it out:
*/
@function calculateRem($size) {
$remSize: $size / 16px;
@return $remSize * 1rem;
}
@mixin font-size-2($size) {
font-size: $size;
font-size: calculateRem($size);
}
/* example of usage */
p {
@include font-size-2(14px);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment