Skip to content

Instantly share code, notes, and snippets.

@yaquawa
Created March 2, 2017 16:52
Show Gist options
  • Save yaquawa/4b532e8720883198acbe4799586c0dd4 to your computer and use it in GitHub Desktop.
Save yaquawa/4b532e8720883198acbe4799586c0dd4 to your computer and use it in GitHub Desktop.
Mixin to generate responsive font size. https://websemantics.uk/articles/responsive-fonts/
@mixin responsive-font-size($max-font-size,$min-font-size,$max-viewport-width,$min-viewport-width) {
@media (min-width: $min-viewport-width) {
:root {
$font-size-difference: $max-font-size - $min-font-size;
$viewport-width-difference: $max-viewport-width - $min-viewport-width;
font-size: calc(100% + ((1vw - #{$min-viewport-width / 100}) * #{100 * $font-size-difference / $viewport-width-difference}));
}
}
// Stop font scaling above $max-viewport-width
@media (min-width: $max-viewport-width) {
:root {
font-size: $max-font-size;
}
}
}
@include responsive-font-size(2em, 1em, 120em, 48em);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment