/// @type Number
$header-margin-bottom: 0.5rem !default;
+/// Styles for headings at various screen sizes. Each key is a breakpoint, and each value is a map of font-size, line-height, margin-top and margin-bottom.
+/// @type Map
+$header-styles: (
+ 'small': (
+ 'h1': ('font-size': 24),
+ 'h2': ('font-size': 20),
+ 'h3': ('font-size': 19),
+ 'h4': ('font-size': 18),
+ 'h5': ('font-size': 17),
+ 'h6': ('font-size': 16)
+ ),
+ 'medium': (
+ 'h1': ('font-size': 48),
+ 'h2': ('font-size': 40),
+ 'h3': ('font-size': 31),
+ 'h4': ('font-size': 25),
+ 'h5': ('font-size': 20),
+ 'h6': ('font-size': 16)
+ )
+) !default;
+
/// Text rendering method of headers.
/// @type String
$header-text-rendering: optimizeLegibility !default;
h4,
h5,
h6 {
- margin-top: 0;
- margin-bottom: $header-margin-bottom;
-
font-family: $header-font-family;
font-style: $header-font-style;
font-weight: $header-font-weight;
}
}
- // Heading sizes
- @each $size, $headers in $header-sizes {
+ // Heading styles
+ @each $size, $headers in $header-styles {
@include breakpoint($size) {
- @each $header, $font-size in $headers {
+ @each $header, $header-defs in $headers {
#{$header} {
- font-size: rem-calc($font-size);
+ @if map-has-key($header-defs, margin-top) {
+ margin-top: rem-calc(map-get($header-defs, margin-top));
+ } @else if map-has-key($header-defs, mt) {
+ margin-top: rem-calc(map-get($header-defs, mt));
+ } @else {
+ margin-top: 0;
+ }
+ @if map-has-key($header-defs, margin-bottom) {
+ margin-bottom: rem-calc(map-get($header-defs, margin-bottom));
+ } @else if map-has-key($header-defs, mb) {
+ margin-bottom: rem-calc(map-get($header-defs, mb));
+ } @else {
+ margin-bottom: rem-calc($header-margin-bottom);
+ }
+
+ @if map-has-key($header-defs, font-size) {
+ font-size: rem-calc(map-get($header-defs, font-size));
+ } @else if map-has-key($header-defs, fs) {
+ font-size: rem-calc(map-get($header-defs, fs));
+ } @else {
+ font-size: 1rem;
+ }
+ @if map-has-key($header-defs, line-height) {
+ line-height: unitless-calc(map-get($header-defs, line-height));
+ } @else if map-has-key($header-defs, lh) {
+ line-height: unitless-calc(map-get($header-defs, lh));
+ } @else {
+ line-height: unitless-calc($header-lineheight);
+ }
}
}
}
@return $value;
}
+
+/// Converts a pixel, percentage, rem or em value to a unitless value based on a given font size. Ideal for working out unitless line heights.
+///
+/// @param {Number} $value - Value to convert to a unitless line height
+/// @param {Number} $base - The font size to use to work out the line height - defaults to $global-font-size
+///
+/// @return {Number} - Unitless number
+@function unitless-calc($value, $base: null) {
+
+ // If no base is defined, defer to the global font size
+ @if $base == null {
+ $base: $global-font-size;
+ }
+
+ // First, lets convert our $base to pixels
+
+ // If the base font size is a %, then multiply it by 16px
+ @if unit($base) == '%' {
+ $base: ($base / 100%) * 16px;
+ }
+
+ @if unit($base) == 'rem' {
+ $base: strip-unit($base) * 16px;
+ }
+
+ @if unit($base) == 'em' {
+ $base: strip-unit($base) * 16px;
+ }
+
+ // Now lets convert our value to pixels too
+ @if unit($value) == '%' {
+ $value: ($value / 100%) * 16px;
+ }
+
+ @if unit($value) == 'rem' {
+ $value: strip-unit($value) * 16px;
+ }
+
+ @if unit($value) == 'em' {
+ $value: strip-unit($value) * 16px;
+ }
+
+ @if type-of($value) == 'number' and not unitless($value) {
+ @return strip-unit($value) / strip-unit($base);
+ }
+
+ @return $value;
+}