Skip to content

Instantly share code, notes, and snippets.

@mrrocks
Created October 14, 2012 14:41
Show Gist options
  • Save mrrocks/3888793 to your computer and use it in GitHub Desktop.
Save mrrocks/3888793 to your computer and use it in GitHub Desktop.
SCSS (Sass) mixin to define font-size in PX, line-height and font-smoothing and then convert it to rem (base 10)
// Sets up the base 10 stuff
html { font-size: 62.5%; }
// Defaults values
$default-line-height: 1.5 !default;
$default-font-smoothing: subpixel-antialiased !default;
// Function to convert pixels to rems
@function px-to-rem($size) {
@return ($size / 10) + rem;
}
// Mixin
@mixin font-size($fs: false, $lh: $default-line-height, $sm: $default-font-smoothing ) {
@if $fs {
font-size: $fs + px;
font-size: px-to-rem($fs);
}
@if $lh { line-height: $lh; }
@if $sm { -webkit-font-smoothing: $sm; }
}
// Use
@include font-size($fs: 14px, $sm: subpixel-antialiased, $lh: 1.5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment