Skip to content

Instantly share code, notes, and snippets.

@jonnymaceachern
Last active July 17, 2017 17:42
Show Gist options
  • Save jonnymaceachern/a07a7fda3387ca7cdc1c96945ef472b1 to your computer and use it in GitHub Desktop.
Save jonnymaceachern/a07a7fda3387ca7cdc1c96945ef472b1 to your computer and use it in GitHub Desktop.
Fluid font-sizes
/// Remove the unit of a length
/// @param {Number} $number - Number to remove unit from
/// @return {Number} - Unitless number
@function strip-unit($number) {
@if type-of($number) == 'number' and not unitless($number) {
@return $number / ($number * 0 + 1);
}
@return $number;
}
// -----------------------------------------------------------------------------
// Fluid font size
// -----------------------------------------------------------------------------
@mixin fluid-font-size($min, $max) {
font-size: $min;
@include mq(xs) {
font-size: calc(#{$min} + #{strip-unit($max - $min)} * ((100vw - #{map-get($mq-breakpoints, xs)}) / (#{strip-unit(map-get($mq-breakpoints, md))})));
}
@include mq(md) {
font-size: $max;
}
}
.lead {
margin-bottom: 25px;
font-weight: 300;
@include fluid-font-size(14px, 22px);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment