Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fluid type scale #216

Open
wants to merge 13 commits into
base: prod
Choose a base branch
from
2 changes: 1 addition & 1 deletion assets/css/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// 3. Base stuff
@import 'base/custom-properties', 'base/fonts', 'base/base', 'base/selection',
'base/typography', './base/a', 'base/helpers';
'base/typography','base/type-scale', './base/a', 'base/helpers';

// 4. Layout-related sections
@import 'structures/header', 'structures/footer', 'structures/grid',
Expand Down
9 changes: 6 additions & 3 deletions assets/css/base/_base.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
@import 'typography';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We import this in css/base.scss, I think you were adding this here because otherwise the SASS variables you are defining in the typography partial would not be accessible?

Two ways to mitigate this, both cleaning up the structure a bit:

  • Define the SASS variables in abstracts/variables (or in base/_fonts where the font weights and families are defined)
  • Change the SASS variables to custom properties and define them in base/custom-properties


body {
border-top: 1rem solid $primary-color;
font-family: $sans-serif;
font-size: pxToRem(20);
font-size: var(--step0);
line-height: $line-height-heading;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you adding $line-height-heading to the body element? I see that you are overwriting this in multiple places down below. I would propose adding $line-height-body here (because it’s the body) and delete all places were you are setting $line-height-body on other elements. Headlines etc. can still have the deviating line-height. This way we let the cascade of CSS work for us.

Suggested change
line-height: $line-height-heading;
line-height: $line-height-body;

margin: 0;
padding: 2rem;
}
Expand All @@ -11,7 +14,7 @@ code {
border: pxToRem(1px) solid $black;
border-radius: 0.25em;
color: $white;
font-size: 95%;
font-size: var(--step-2);
padding: 0.15em;

pre & {
Expand All @@ -33,5 +36,5 @@ th {
}

pre[class*='language-'] {
font-size: 1rem;
font-size: var(--step-1);
}
74 changes: 74 additions & 0 deletions assets/css/base/_type-scale.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
@use "sass:map";

/// Create new/different scales by editing the config
/// This is the single source of truth
$fluid-config: (
// Typescale ratio for calculating steps
typescale-ratio: 1.25,
// base font size to use for --step0
base-fontsize: 1rem,
// adjustment added to base-fontsize in --step0 for scaling
viewport-scale: 0.5vw,
// number of positive steps (--step1, --step2 etc)
// and number of negative steps (--step-1, --step-2 etc)
Comment on lines +12 to +13
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These names are not really clear. Hyphenating is common to separate words, especially in CSS where we don’t use camel case. Can you change these two be either --step-pos-1 and --step-neg-1 or for positive use --step-1 (as this is what we mostly use) and only namespace the negative variables, e.g. --step-minus-1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Will update

steps:
(
pos: 10,
neg: 3
)
);

/// Creates all required css step variables
/// for the type scale
///
/// @param {number} $typescale-ratio
/// The ratio we use to compute steps.
/// @example
/// --step1 : calc(var(--step0 * #{$typescale-ratio}))
///
/// @param {integer (rem)} $base-fontsize
/// The base fontsize we use for step0
/// @param {integer (vw)} $viewport-scale
/// adjustment added to base-fontsize for scaling
/// @example
/// --step0: calc(#{$base-fontsize}+#{$viewport-scale})
///
/// @param {map} $steps
/// no of positive and negative steps to create in font scales
/// @example
/// $steps: (pos: 7, neg: 3)

@mixin create-typescale(
$typescale-ratio,
$base-fontsize,
$viewport-scale,
$steps
) {
$pos-steps: map.get($steps, pos);
$neg-steps: map.get($steps, neg);
--step0: calc(#{$base-fontsize} + #{$viewport-scale});
@for $step from 1 to $pos-steps {
& {
--step#{$step}: calc(var(--step#{$step - 1}) * #{$typescale-ratio});
}
}

@for $step from 1 to $neg-steps {
// to account for the lack of dash(-) in step0
// --step-0 doesn't exist so we need to use a different expression
// while computing --step-1
@if $step != 1 {
& {
--step-#{$step}: calc(var(--step-#{$step - 1}) / #{$typescale-ratio});
}
} @else {
& {
--step-#{$step}: calc(var(--step0) / #{$typescale-ratio});
}
}
}
}

:root {
@include create-typescale($fluid-config...);
}
74 changes: 34 additions & 40 deletions assets/css/base/_typography.scss
Original file line number Diff line number Diff line change
@@ -1,63 +1,57 @@
$line-height-heading: 1;
$line-height-body: 1.4;
$line-height-tight: 0.8;

h1 {
font-family: $ext-sans;
font-weight: $bold;
font-family: $ext-sans;
font-weight: $bold;
line-height: $line-height-heading;
}

h1,
h2,
h3,
h4 {
margin-bottom: 0.5em;
margin-top: 1em;
word-break: break-word;
line-height: $line-height-heading;
margin-bottom: 0.5em;
margin-top: 1em;
word-break: break-word;
}

p {
font-size: 1.25rem;
line-height: 1.25;
margin: 0.75rem 0;
}

.thicc-headline {
// a sensible base font size
font-size: 3rem;
line-height: 0.75;
margin: 0.5rem 0rem;
padding: 0;
font-size: var(--step-1);
line-height: $line-height-body;
margin: 0.75rem 0;
}

@media (min-width: 51rem) and (min-height: 400px) {
// a dramatic font size
.thicc-headline {
font-size: 12vh;
}
li {
font-size: var(--step-1);
line-height: $line-height-body;
}

@media (min-width: 51rem) and (min-height: 850px) {
// cap the maximum font size of the title
// at the same size that 12vh computes to
// when the viewport is 850px high
// One day we can use CSS clamp https://caniuse.com/#feat=mdn-css_types_clamp
.thicc-headline {
font-size: 6.75rem;
}
.thicc-headline {
font-size: var(--step6);
line-height: $line-height-tight;
margin: 0.5rem 0;
padding: 0;
}

.main-headline {
font-family: orpheuspro, Palatino, Times, serif;
font-size: 3.5rem;
line-height: 1.2;
margin: 0;
font-family: orpheuspro, Palatino, Times, serif;
font-size: var(--step4);
line-height: $line-height-heading;
margin: 0;
}

.sub-headline {
font-family: $ext-sans;
font-size: 1.25rem;
font-weight: $bold;
letter-spacing: 0.1;
margin: .75rem 0;
font-family: $ext-sans;
font-size: var(--step0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe step-0 is not the correct value here, as .sub-headline should be larger then the body text.

font-weight: $bold;
letter-spacing: 0.01rem;
line-height: $line-height-heading;
margin: 0.75rem 0;
}

.small {
font-size: 0.75em;
font-size: var(--step-1);
line-height: $line-height-body;
}
28 changes: 14 additions & 14 deletions assets/css/components/_definitions.scss
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
.word__type {
font-family: $con-sans;
font-size: 0.85rem;
padding-right: 1rem;
text-align: right;
text-transform: uppercase;
}
font-family: $con-sans;
font-size: var(--step-2);
padding-right: 1rem;
text-align: right;
text-transform: uppercase;
}

.word__link {
border-bottom: darkgrey solid 0.1em;
color: black;
font-family: $ext-sans;
text-decoration: none;
}
border-bottom: darkgrey solid 0.1em;
color: black;
font-family: $ext-sans;
text-decoration: none;
}

.word__breakdown {
border-left: 0.1rem solid lightgrey;
font-family: $sans-serif;
padding-left: 1rem;
border-left: 0.1rem solid lightgrey;
font-family: $sans-serif;
padding-left: 1rem;
}

.content-flag {
Expand Down
5 changes: 2 additions & 3 deletions assets/css/components/_flag.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.flag {
border-radius: 1rem;
display: inline-block;
font-size: 0.9rem;
font-size: var(--step-1);
font-weight: bold;
margin: 0.5rem 0.75rem 0.25rem 0;
padding: 0.45rem 0.65rem;
Expand All @@ -15,10 +15,9 @@
}
&--yellow {
background-color: $lt-background-color-warning;

&:before {
@include icon__warning();
@include icon__embed();
}
}
}
}
10 changes: 5 additions & 5 deletions assets/css/components/_word.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

&__title {
font-family: $serif;
font-size: 2.5rem;
font-size: var(--step2);
font-weight: 900;
line-height: 1.25;
margin-bottom: 1rem;
Expand All @@ -26,14 +26,14 @@

& > p {
font-family: $sans-serif;
font-size: 1.5rem;
font-size: var(--step1);
grid-column: 1 / -1;
}

& h4 {
flex: 0 1 auto;
font-family: $con-sans;
font-size: 0.85rem;
font-size: var(--step2);
font-weight: normal;
grid-column: 1;
text-transform: uppercase;
Expand All @@ -60,15 +60,15 @@

&__speech {
font-family: $sans-serif;
font-size: 0.5em;
font-size: var(--step-3);
}

&__signal {
border-top: pxToRem(1) solid var(--word-signal-color);
color: var(--word-signal-color);
display: inline-block;
font-family: $ext-sans;
font-size: 0.75rem;
font-size: var(--step-2);
letter-spacing: 0.15rem;
padding: 0.5rem 0.75rem;
text-transform: uppercase;
Expand Down
4 changes: 4 additions & 0 deletions assets/css/layouts/_pages.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
}
}

.wide-content .title p {
font-size: var(--step-2);
}

.definition {
max-width: 47rem;
}
Expand Down
11 changes: 6 additions & 5 deletions assets/css/structures/_definition-content.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

&__title {
font-family: $serif;
font-size: 2.5rem;
font-size: var(--step3);
font-weight: 900;
line-height: 1.25;
margin-bottom: 1rem;
Expand All @@ -31,17 +31,18 @@

& > p {
font-family: $sans-serif;
font-size: 1.5rem;
font-size: var(--step0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you changed this here because 1.5rem made the first paragraph in definition mostly unreadable on mobile?

grid-column: 1 / -1;
line-height: 1.4;
line-height: $line-height-body;
}

& h2 {
flex: 0 1 auto;
font-family: $con-sans;
font-size: 0.85rem;
font-size: var(--step-2);
font-weight: normal;
grid-column: 1;
line-height: $line-height-body;
text-transform: uppercase;
transform: translateY(0.4em);

Expand Down Expand Up @@ -75,7 +76,7 @@
color: var(--word-signal-color);
display: block;
font-family: $ext-sans;
font-size: 0.75rem;
font-size: var(--step-2);
letter-spacing: 0.15rem;
padding: 0.5rem 0.75rem;
text-transform: uppercase;
Expand Down
2 changes: 1 addition & 1 deletion assets/css/structures/_definition-navigation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

.definition-navigation__sub-headline {
color: #333;
font-size: 1rem;
font-size: var(--step-1);
font-variant-caps: all-small-caps;
letter-spacing: 0.01em;
margin-top: 0;
Expand Down