Responsive Typography · Responsive Typography • Changing values at breakpoints • Base font...

27
Responsive Typography Using Sass to Keep Things Legible

Transcript of Responsive Typography · Responsive Typography • Changing values at breakpoints • Base font...

Page 1: Responsive Typography · Responsive Typography • Changing values at breakpoints • Base font size • Scale interval • Vertical Rhythm

Responsive Typography

Using Sass to Keep Things Legible

Page 2: Responsive Typography · Responsive Typography • Changing values at breakpoints • Base font size • Scale interval • Vertical Rhythm

What Is Responsive Typography?

Page 3: Responsive Typography · Responsive Typography • Changing values at breakpoints • Base font size • Scale interval • Vertical Rhythm

Web Typography

• Font faces • Sizes & scale • Line height & vertical rhythm • Line length

Page 4: Responsive Typography · Responsive Typography • Changing values at breakpoints • Base font size • Scale interval • Vertical Rhythm

Responsive Typography

• Changing values at breakpoints • Base font size • Scale interval • Vertical Rhythm

Page 5: Responsive Typography · Responsive Typography • Changing values at breakpoints • Base font size • Scale interval • Vertical Rhythm

Why DoesResponsive Typography

Matter?

Page 6: Responsive Typography · Responsive Typography • Changing values at breakpoints • Base font size • Scale interval • Vertical Rhythm
Page 7: Responsive Typography · Responsive Typography • Changing values at breakpoints • Base font size • Scale interval • Vertical Rhythm
Page 8: Responsive Typography · Responsive Typography • Changing values at breakpoints • Base font size • Scale interval • Vertical Rhythm
Page 9: Responsive Typography · Responsive Typography • Changing values at breakpoints • Base font size • Scale interval • Vertical Rhythm
Page 10: Responsive Typography · Responsive Typography • Changing values at breakpoints • Base font size • Scale interval • Vertical Rhythm

How Do We MakeResponsive Typography

Easy?

Page 11: Responsive Typography · Responsive Typography • Changing values at breakpoints • Base font size • Scale interval • Vertical Rhythm

to the Rescue!

Page 12: Responsive Typography · Responsive Typography • Changing values at breakpoints • Base font size • Scale interval • Vertical Rhythm

Map for Storing Data

• Breakpoint widths • Typography values

• Base font-size • Scale • Vertical Rhythm

Page 13: Responsive Typography · Responsive Typography • Changing values at breakpoints • Base font size • Scale interval • Vertical Rhythm

Map

$rwd-typography: ( default: ( base-font-size: 16px, vertical-rhythm: 1.414, type-scale: 1.2, min-width: null ), );

Page 14: Responsive Typography · Responsive Typography • Changing values at breakpoints • Base font size • Scale interval • Vertical Rhythm

Map

$rwd-typography: ( medium: ( base-font-size: 18px, vertical-rhythm: 1.5, type-scale: 1.414, min-width: 480px ), );

Page 15: Responsive Typography · Responsive Typography • Changing values at breakpoints • Base font size • Scale interval • Vertical Rhythm

Map

$rwd-typography: ( large: ( base-font-size: 20px, vertical-rhythm: 1.618, type-scale: 1.5, min-width: 960px ), );

Page 16: Responsive Typography · Responsive Typography • Changing values at breakpoints • Base font size • Scale interval • Vertical Rhythm

Map

$rwd-typography: ( xlarge: ( base-font-size: 24px, vertical-rhythm: 1.618, type-scale: 1.618, min-width: 1300px ) );

Page 17: Responsive Typography · Responsive Typography • Changing values at breakpoints • Base font size • Scale interval • Vertical Rhythm

List for Storing Labels

• Generate multiple font-sizes on a consistent scale

• Labels to assign those sizes to

Page 18: Responsive Typography · Responsive Typography • Changing values at breakpoints • Base font size • Scale interval • Vertical Rhythm

List

$rwd-labels: ( p, bq, sh, h, hero );

Page 19: Responsive Typography · Responsive Typography • Changing values at breakpoints • Base font size • Scale interval • Vertical Rhythm

Loop through Labels

@each $label in $rwd-labels { %#{$label} { // loop through breakpoints } }

Page 20: Responsive Typography · Responsive Typography • Changing values at breakpoints • Base font size • Scale interval • Vertical Rhythm

Loop through Breakpoints

@each $bp, $data in $rwd-typography { // $bp = key // $data = value: nested map // font-size: ?; // line-height: ?; }

Page 21: Responsive Typography · Responsive Typography • Changing values at breakpoints • Base font size • Scale interval • Vertical Rhythm

Get Font-Size

@function rwd-get-font-size($label, $bp) { $base—font-size: map-get(map-get($rwd-typography, $bp), base-font-size); $type-scale: map-get(map-get($rwd-typography, $bp), type-scale); $return: $base-font-size; @for $i from 1 to index($rwd-labels, $label) { $return: $return * $type-scale; } @return $return; }

Page 22: Responsive Typography · Responsive Typography • Changing values at breakpoints • Base font size • Scale interval • Vertical Rhythm

Get Line-Height

@function rwd-get-font-size($label, $bp) { // same as before, but new var - $font-size $font-size: X;   $vertical-rhythm: map-get(map-get($rwd-typography, $bp), vertical-rhythm); $vertical-rhythm: $base-font-size * $vertical-rhythm; $line-height: ceil($font-size / $vertical-rhythm) * $vertical-rhythm / $font-size; $return: join($font-size, $line-height); @return $return; }

Page 23: Responsive Typography · Responsive Typography • Changing values at breakpoints • Base font size • Scale interval • Vertical Rhythm

Using the Values

$values: rwd-generate-font-size($label, $bp);

font-size: nth($values, 1); line-height: nth($values, 2);

Page 24: Responsive Typography · Responsive Typography • Changing values at breakpoints • Base font size • Scale interval • Vertical Rhythm

Extending the Labels

body { @extend %p; }

blockquote { @extend %bq; }

h2 { @extend %sh; }

h1 { @extend %h1; }

.hero { @extend %hero; }