Created
November 30, 2016 23:21
-
-
Save paulfarino/7a46772952d3e0faecd1e74423f887f7 to your computer and use it in GitHub Desktop.
Typography SCSS
This file contains hidden or 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
| // Round number to 2 decimal places | |
| @function decimal-round ($number, $digits: 0, $mode: round) { | |
| $n: 1; | |
| // $number must be a number | |
| @if type-of($number) != number { | |
| @warn '#{ $number } is not a number.'; | |
| @return $number; | |
| } | |
| // $digits must be a unitless number | |
| @if type-of($digits) != number { | |
| @warn '#{ $digits } is not a number.'; | |
| @return $number; | |
| } @else if not unitless($digits) { | |
| @warn '#{ $digits } has a unit.'; | |
| @return $number; | |
| } | |
| @for $i from 1 through $digits { | |
| $n: $n * 10; | |
| } | |
| @if $mode == round { | |
| @return round($number * $n) / $n; | |
| } @else if $mode == ceil { | |
| @return ceil($number * $n) / $n; | |
| } @else if $mode == floor { | |
| @return floor($number * $n) / $n; | |
| } @else { | |
| @warn '#{ $mode } is undefined keyword.'; | |
| @return $number; | |
| } | |
| } | |
| // Type | |
| $base: 16px; | |
| @mixin headings($from: 1, $to: 6){ | |
| @for $i from $from through $to{ | |
| h#{$i}{ | |
| @content; | |
| font-size: decimal-round($base * 4.25 / $i); | |
| } | |
| } | |
| } | |
| @include headings(){ | |
| font-family:sans-serif; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment