Created
December 6, 2013 14:31
-
-
Save lolmaus/7825675 to your computer and use it in GitHub Desktop.
A mixin used to generate heading sizes. You provide min and max heading sizes and it calculates all the sizes in between. The sizes can be calculated proportionally or augmented by a ratio. Note that calculating based on a ratio requires the modular-scale extension.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Requires modular-scale | |
=heading-sizes($max-size: 30px, $min-size: 16px, $max-heading: 1, $min-heading: 6, $ratio: 1, $debug: false) | |
$number-of-headings: $min-heading - $max-heading + 1 | |
$scaled-size-of-max-heading: modular-scale($number-of-headings - 1, $min-size, $ratio) | |
$coefficient: 0 | |
@if $ratio != 1 | |
@if modular-scale(1, 1, octave()) != 2 | |
@warn "Using heading-sizes with a ratio other than 1 requires modular-scale." | |
$coefficient: ($scaled-size-of-max-heading - $min-size) / ($max-size - $min-size) | |
@for $i from 1 through $number-of-headings | |
$heading: $number-of-headings - $i + $max-heading | |
h#{$heading} | |
$size: foo | |
@if $ratio == 1 | |
$size-without-min: $max-size - $min-size | |
$increment: $size-without-min / ($number-of-headings - 1) | |
$current-increment: $increment * ($i - 1) | |
$size: $min-size + $current-increment | |
@else | |
$scaled-size: modular-scale($i - 1, $min-size, $ratio) | |
$difference: $scaled-size - $min-size | |
$shrinked-difference: $difference / $coefficient | |
$size: $min-size + $shrinked-difference | |
font-size: $size | |
@if $debug | |
&:after | |
content: "#{$size}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment