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

Responsive typography function #212

Open
peeke opened this issue Jan 12, 2021 · 0 comments
Open

Responsive typography function #212

peeke opened this issue Jan 12, 2021 · 0 comments

Comments

@peeke
Copy link
Contributor

peeke commented Jan 12, 2021

When defining a responsive font-size, we use the following css:

:root {
  --font-size-unit: 1px;
  --font-size-viewport-min: 480;
  --font-size-viewport-max: 1920;

  --font-size-growth: calc(1 / (var(--font-size-viewport-max) - var(--font-size-viewport-min)));
  --m: calc((var(--font-size-growth) * 100vw) - (var(--font-size-growth) * var(--font-size-viewport-min) * var(--font-size-unit)));
}

--font-size-16-18: clamp(16px, calc(16px + 2 * var(--m)), 18px);

It would be nice if we can abstract this away to a custom postcss function. In that case, the calculation could be inlined to avoid any dependencies on custom properties.

Something like:

font-size: responsive-font-size(18px, 28px, 480px, 1920px);

Which transforms into:

font-size: clamp(
  18px, 
  18px + 14 * (
    (1 / (1920 - 480) * 100vw) - 
    (1 / (1920 - 480) * 480px)
  ),
  32px
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant