Skip to content

Instantly share code, notes, and snippets.

@webbower
Created February 28, 2014 04:51
Show Gist options
  • Save webbower/9265459 to your computer and use it in GitHub Desktop.
Save webbower/9265459 to your computer and use it in GitHub Desktop.
SCSS font-size mixin for using rems with fallback
// strip-unit function courtest of Karl Merkli http://css-tricks.com/snippets/css/less-mixin-for-rem-font-sizing/
@function strip-unit($num) {
@return $num / ($num * 0 + 1);
}
// $size arg is the desired font size in pixels (e.g. @include font-size(16px);)
// Requires a $base-font-size variable be set and used like so:
//
// $base-font-size: 16px;
//
// // Later...
//
// html {
// font-size: $base-font-size;
// }
@mixin font-size($size) {
$raw-value: strip-unit($size);
$raw-base-value: strip-unit($base-font-size);
font-size: $raw-value + px;
font-size: ($raw-value / $raw-base-value) + rem;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment