Skip to content

Instantly share code, notes, and snippets.

@06b
Created December 10, 2020 19:12
Show Gist options
  • Save 06b/3118a468830057981513a07c19f60127 to your computer and use it in GitHub Desktop.
Save 06b/3118a468830057981513a07c19f60127 to your computer and use it in GitHub Desktop.
How to calculate a decreased line-height for wrapped headlines when using a typographic scale.
:root {
--phi: 1.618033988749895;
--perfect-fourth: calc(4/3);
}
html {
line-height: 1.5;
line-height: var(--phi);
}
h1,
h2,
h3,
h4,
h5,
h6 {
line-height: 1.125;
/**
* Theorem:
* If a typographic scale is used then it is possible to calculate a decreased line-height for wrapped headlines
* by dividing the current line-height by the ratio of the typographic scale.
*
* 𝒍 Γ· 𝒓 = 𝑫
*
* Proof:
* 𝑹 βˆ‹ {𝒇ⁿ,𝒇ⁿ⁺¹,𝒇ⁿ⁺²,…}, 𝒇ⁿ⁺¹ Γ· 𝒇ⁿ = 𝒓, 𝒇 Γ— 𝒍 = 𝒉 β‡’ 𝒉 Γ· 𝒓 = (𝒇×𝑫) β‡’ (𝒇×𝑫) Γ· 𝒇 = 𝑫 β‡’ 𝑫 = 𝒍 Γ· 𝒓.∎
*
* Let 𝑹 denote a set of values in which represent a typographic scale,
* 𝒇 denote a value within 𝑹 that represents the font-size absolute length with the unit identifier omitted,
* 𝒓 denote the ratio of the typographic scale between 𝒇ⁿ & 𝒇ⁿ⁺¹,
* 𝒍 denote a (~) unitless line-height,
* 𝒉 denote the computed value of 𝒇×𝒍,
* and finally 𝑫 denote the decreased line-height.
*
* Case 1:
* Assume 𝑹 βˆ‹ {19, 25.333, 33.777,…} where 𝒇ⁿ⁺¹ = 33.777 & 𝒇ⁿ = 25.333.
* 33.777 Γ· 25.333 β‰ˆ 1.333 = 𝒓, which can also be viewed as 𝒓 β‰ˆ (4/3) β‰ˆ 1.333.
* 𝒇 = 19 & 𝒍 = 1.5 β‡’ 19 Γ— 1.5 = 𝒉 β‡’ 𝒉 = 28.5 β‡’
* 28.5 Γ· (4/3) = 21.375 = (𝒇×𝑫) β‡’
* 21.375 Γ· 19 = 1.125 = 𝑫 β‡’
* 1.125 = 1.5 ÷ 1.333.∎
*
* Case 2:
* Assume 𝒓 = (4/3), 𝒍 = Ο† where β‰ˆ 1.6180339887…,
* 𝒍 Γ· 𝒓 = 𝑫 β‡’ Ο† Γ· 𝒓,
* 1.6180339887… Γ· (4/3) β‰ˆ 1.213525β€¦βˆŽ
*
*/
line-height: calc(var(--phi)/var(--perfect-fourth));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment