Skip to content

Commit

Permalink
Adds responsive font size mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
arielsalminen committed Nov 4, 2017
1 parent 576053a commit faee404
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/styles/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,42 @@
/* GLOBAL MIXINS
--------------------------------------------- */

/* AUTO SCALING FOR TYPE WITH MIN/MAX SIZES
@param {Number} $responsive - Viewport-based size
@param {Number} $min - Minimum font size (px)
@param {Number} $max - Maximum font size (px) (optional)
@param {Number} $fallback - Fallback for viewport-based units (optional)
@example SCSS - 5vw size, 35px min & 150px max size + 50px fallback:
@include responsive-font(5vw, 35px, 150px, 50px);
*/
@mixin responsive-font($responsive, $min, $max: false, $fallback: false) {
$responsive-unitless: $responsive / ($responsive - $responsive + 1);
$dimension: if(unit($responsive) == 'vh', 'height', 'width');
$min-breakpoint: $min / $responsive-unitless * 100;

@media (max-#{$dimension}: #{$min-breakpoint}) {
font-size: $min;
}

@if $max {
$max-breakpoint: $max / $responsive-unitless * 100;

@media (min-#{$dimension}: #{$max-breakpoint}) {
font-size: $max;
}
}

@if $fallback {
font-size: $fallback;
}

font-size: $responsive;
}

// Reset
@mixin reset {
box-sizing: border-box;
Expand Down

0 comments on commit faee404

Please sign in to comment.