Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 67 additions & 4 deletions docs/pages/typography-base.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,78 @@ Foundation includes styles for all headings—they're balanced and sized alo

---

### Header Sizes
### Header Styles

The framework includes two typographic scales&mdash;one uses a narrow range of sizes for small- and medium-sized screens, and the other uses a wider range of sizes for large-sized screens. You can change these scales, or add new ones for other breakpoints, by editing the `$header-sizes` map in your project's <a href="sass.html#the-settings-file">Settings File</a>.
The framework includes two typographic scales&mdash;one uses a narrow range of sizes for small-sized screens, and the other uses a wider range of sizes for medium- and larger-sized screens. You can change these scales, or add new ones for other breakpoints, by editing the `$header-styles` map in your project's <a href="sass.html#the-settings-file">Settings File</a>.

Header | Default | Large and up
--------|---------|-------------
Header | Default | Medium and up
--------|---------|--------------
`<h1>` | 24px | 48px
`<h2>` | 20px | 40px
`<h3>` | 19px | 31px
`<h4>` | 18px | 25px
`<h5>` | 17px | 20px
`<h6>` | 16px | 16px

You can also adjust line height, margin top and margin bottom for each heading size by adding values in your <a href="sass.html#the-settings-file">Settings File</a>.

In its most complete form the `$header-styles` map looks like this:

```
$header-styles: (
'small': (
'h1': ('font-size': 24, 'line-height': $header-lineheight, 'margin-top': 0, 'margin-bottom': $header-margin-bottom),
'h2': ('font-size': 20, 'line-height': $header-lineheight, 'margin-top': 0, 'margin-bottom': $header-margin-bottom),
'h3': ('font-size': 19, 'line-height': $header-lineheight, 'margin-top': 0, 'margin-bottom': $header-margin-bottom),
'h4': ('font-size': 18, 'line-height': $header-lineheight, 'margin-top': 0, 'margin-bottom': $header-margin-bottom),
'h5': ('font-size': 17, 'line-height': $header-lineheight, 'margin-top': 0, 'margin-bottom': $header-margin-bottom),
'h6': ('font-size': 16, 'line-height': $header-lineheight, 'margin-top': 0, 'margin-bottom': $header-margin-bottom)
),
'medium': (
'h1': ('font-size': 48, 'line-height': $header-lineheight, 'margin-top': 0, 'margin-bottom': $header-margin-bottom),
'h2': ('font-size': 40, 'line-height': $header-lineheight, 'margin-top': 0, 'margin-bottom': $header-margin-bottom),
'h3': ('font-size': 31, 'line-height': $header-lineheight, 'margin-top': 0, 'margin-bottom': $header-margin-bottom),
'h4': ('font-size': 25, 'line-height': $header-lineheight, 'margin-top': 0, 'margin-bottom': $header-margin-bottom),
'h5': ('font-size': 20, 'line-height': $header-lineheight, 'margin-top': 0, 'margin-bottom': $header-margin-bottom),
'h6': ('font-size': 16, 'line-height': $header-lineheight, 'margin-top': 0, 'margin-bottom': $header-margin-bottom)
),
...
);
```

Because this is a little bit lengthy we have also introduced a short form, that you can use alternatively:

```
$header-styles: (
'small': (
'h1': ('fs': 24, 'lh': $header-lineheight, 'mt': 0, 'mb': $header-margin-bottom),
'h2': ('fs': 20, 'lh': $header-lineheight, 'mt': 0, 'mb': $header-margin-bottom),
'h3': ('fs': 19, 'lh': $header-lineheight, 'mt': 0, 'mb': $header-margin-bottom),
'h4': ('fs': 18, 'lh': $header-lineheight, 'mt': 0, 'mb': $header-margin-bottom),
'h5': ('fs': 17, 'lh': $header-lineheight, 'mt': 0, 'mb': $header-margin-bottom),
'h6': ('fs': 16, 'lh': $header-lineheight, 'mt': 0, 'mb': $header-margin-bottom)
),
'medium': (
'h1': ('fs': 48, 'lh': $header-lineheight, 'mt': 0, 'mb': $header-margin-bottom),
'h2': ('fs': 40, 'lh': $header-lineheight, 'mt': 0, 'mb': $header-margin-bottom),
'h3': ('fs': 31, 'lh': $header-lineheight, 'mt': 0, 'mb': $header-margin-bottom),
'h4': ('fs': 25, 'lh': $header-lineheight, 'mt': 0, 'mb': $header-margin-bottom),
'h5': ('fs': 20, 'lh': $header-lineheight, 'mt': 0, 'mb': $header-margin-bottom),
'h6': ('fs': 16, 'lh': $header-lineheight, 'mt': 0, 'mb': $header-margin-bottom)
),
...
);
```

The values for `'font-size'`/`'fs'`, `'margin-top'`/`'mt'` and `'margin-bottom'`/`'mb'` are transformed into 'rem's. You can use any unit, but if you don't, we assume that you mean 'px'. If you do not set the keys `'font-size'`/`'fs'` defaults to `1rem`, `'margin-top'`/`'mt'` to `0` and `'margin-bottom'`/`'mb'` to `$header-margin-bottom` for size `'small'`. Thereafter the values for a larger size are inherited from the values of the smaller size if no value is entered for a larger breakpoint.

The value for `'line-height'`/`'lh'` is transformed into a unitless number, that expresses the line-height relative to the fonts-size. You can also input any unit. If you don't, we assume that for numbers smaller than or equal to 10, you mean a typical relative line-height. However, if you put in anything larger than 10, we assume you mean 'px', since we have not yet seen relative line-heights that were larger than 10. If you do not set `'line-height'`/`'lh'` it defaults to `$header-lineheight` for size `'small'`. Thereafter the value for a larger size is inherited from the values of the smaller size.

<div class="callout alert">
<p><strong>The `$header-styles` map has replaced `$header-sizes` map in version 6.3. `$header-styles` map is a more general map than `$header-sizes`.</strong></p>
<p>`$header-sizes` map is still working and is used to initialize the `$header-styles` map. In a future version `$header-sizes` is going to be depreciated.</p>
</div>

---

### Small Header Segments
Expand Down Expand Up @@ -260,3 +319,7 @@ Foundation includes print styles developed by HTML5 Boilerplate to give you some
- Page cleanup and window minimization

On top of that, Foundation includes a couple of simple classes you can use to control elements printing, or not printing. Simply attach `.show-for-print` to an element to only show when printing, and `.hide-for-print` to hide something when printing.

<div class="callout primary">
<p>Print styles use `!important` to ensure they aren't overriden by more specific selectors. This framework conscientiously avoids using `!important` declarations. This is one of the few components that does.</p>
+</div>
30 changes: 15 additions & 15 deletions scss/settings/_settings.scss
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,22 @@ $header-font-family: $body-font-family;
$header-font-weight: $global-weight-normal;
$header-font-style: normal;
$font-family-monospace: Consolas, 'Liberation Mono', Courier, monospace;
$header-sizes: (
small: (
'h1': 24,
'h2': 20,
'h3': 19,
'h4': 18,
'h5': 17,
'h6': 16,
$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': 48,
'h2': 40,
'h3': 31,
'h4': 25,
'h5': 20,
'h6': 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)
),
);
$header-color: inherit;
Expand Down
106 changes: 77 additions & 29 deletions scss/typography/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,6 @@ $header-font-style: normal !default;
/// @type String | List
$font-family-monospace: Consolas, 'Liberation Mono', Courier, monospace !default;

/// Sizes of headings at various screen sizes. Each key is a breakpoint, and each value is a map of heading sizes.
/// @type Map
$header-sizes: (
small: (
'h1': 24,
'h2': 20,
'h3': 19,
'h4': 18,
'h5': 17,
'h6': 16,
),
medium: (
'h1': 48,
'h2': 40,
'h3': 31,
'h4': 25,
'h5': 20,
'h6': 16,
),
) !default;

/// Color of headers.
/// @type Color
$header-color: inherit !default;
Expand All @@ -71,6 +50,47 @@ $header-lineheight: 1.4 !default;
/// @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 heading styles.
/// @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;

// $header-styles map is built from $header-sizes in order to ensure downward compatibility
// when $header-sizes is depreciated, $header-styles needs to get !default values like settings.scss
@function build_from_header-sizes($header-sizes) {
@warn 'Note, that $header-sizes has been replaced with $header-styles. $header-sizes still works, but it is going to be depreciated.';
$header-styles: ();
@each $size, $headers in $header-sizes {
$header-map: ();
@each $header, $font-size in $headers {
$header-map: map-merge($header-map, ($header: ('font-size': $font-size)));
}
$header-styles: map-merge($header-styles, ($size: $header-map));
}
@return $header-styles;
}

// If it exists $headers-sizes is used to build $header-styles. See the documentation.
@if variable-exists(header-sizes) {
$header-styles: build_from_header-sizes($header-sizes);
}

/// Text rendering method of headers.
/// @type String
$header-text-rendering: optimizeLegibility !default;
Expand Down Expand Up @@ -292,13 +312,9 @@ $abbr-underline: 1px dotted $black !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;
line-height: $header-lineheight;
color: $header-color;
text-rendering: $header-text-rendering;

Expand All @@ -308,12 +324,44 @@ $abbr-underline: 1px dotted $black !default;
}
}

// 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 {
$font-size-temp: 1rem;
#{$header} {
font-size: rem-calc($font-size);

@if map-has-key($header-defs, font-size) {
$font-size-temp: rem-calc(map-get($header-defs, font-size));
font-size: $font-size-temp;
} @else if map-has-key($header-defs, fs) {
$font-size-temp: rem-calc(map-get($header-defs, fs));
font-size: $font-size-temp;
} @else if $size == $-zf-zero-breakpoint {
font-size: $font-size-temp;
}
@if map-has-key($header-defs, line-height) {
line-height: unitless-calc(map-get($header-defs, line-height), $font-size-temp);
} @else if map-has-key($header-defs, lh) {
line-height: unitless-calc(map-get($header-defs, lh), $font-size-temp);
} @else if $size == $-zf-zero-breakpoint {
line-height: unitless-calc($header-lineheight, $font-size-temp);
}

@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 if $size == $-zf-zero-breakpoint {
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 if $size == $-zf-zero-breakpoint {
margin-bottom: rem-calc($header-margin-bottom);
}
}
}
}
Expand Down
61 changes: 60 additions & 1 deletion scss/util/_unit.scss
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ $global-font-size: 100% !default;
@return $value;
}

// Calculate rem if units for $value is not rem
// Transform em into rem if someone hands over 'em's
@if unit($value) == 'em' {
$value: strip-unit($value) * 1rem;
}

// Calculate rem if units for $value is not rem or em
@if unit($value) != 'rem' {
$value: strip-unit($value) / strip-unit($base) * 1rem;
}
Expand All @@ -93,3 +98,57 @@ $global-font-size: 100% !default;

@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%) * $base;
}

@if unit($value) == 'rem' {
$value: strip-unit($value) * $base;
}

@if unit($value) == 'em' {
$value: strip-unit($value) * $base;
}

// 'px'
@if unit($value) == 'px' {
@return strip-unit($value) / strip-unit($base);
}

// assume that line-heights greatern then 10 are meant to be absolute in 'px'
@if unitless($value) and ($value > 10) {
@return $value / strip-unit($base);
}

@return $value;
}
Loading