Skip to content

Instantly share code, notes, and snippets.

@erickjones
Forked from colinmeinke/_unit.scss
Created February 8, 2016 09:10
Show Gist options
  • Save erickjones/5f605d9b5eba722e56d4 to your computer and use it in GitHub Desktop.
Save erickjones/5f605d9b5eba722e56d4 to your computer and use it in GitHub Desktop.
Sass remify/emify mixins
// Defaults
$base_font_size: 16px;
$rem_fallback: true;
// Usage: rem(16px);
@function rem(
$size,
$base_font_size: $base_font_size
) {
@return #{$size / $base_font_size}rem;
}
// Usage: em(16px);
@function em(
$size,
$base_font_size: $base_font_size
) {
@return #{$size / $base_font_size}em;
}
// Usage: @include remify(font-size, 16px);
@mixin remify(
$property,
$size,
$rem_fallback: $rem_fallback,
$base_font_size: $base_font_size
) {
@if $rem_fallback {
#{$property}: $size;
}
#{$property}: rem($size, $base_font_size);
}
// Usage: @include emify(font-size, 16px);
@mixin emify(
$property,
$size,
$base_font_size: $base_font_size
) {
#{$property}: em($size, $base_font_size);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment