Skip to content

Instantly share code, notes, and snippets.

@jhned
Created April 19, 2016 21:19
Show Gist options
  • Save jhned/2c3fd4747b4abb87fb050a9b0822dc41 to your computer and use it in GitHub Desktop.
Save jhned/2c3fd4747b4abb87fb050a9b0822dc41 to your computer and use it in GitHub Desktop.
Flexible font sizes
@function strip-unit($value) {
@return $value / ($value * 0 + 1);
}
@mixin flexible_font_sizes( $min-font-size, $max-font-size, $min-width, $max-width ) {
$font-size-difference: strip-unit($max-font-size - $min-font-size);
$viewport-difference: strip-unit($max-width - $min-width);
@media screen and #{breakpoint($min-width)} and #{breakpoint($max-width down)} {
font-size: calc( #{$min-font-size} + #{$font-size-difference} * ( ( 100vw - #{$min-width} ) / #{$viewport-difference} ) );
}
}
.module-with-flexible-sizes {
@include flexible_font_sizes( 16px, 20px, 320px, 539px );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment