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

Relative font-size support #212

Closed
andriytyurnikov opened this issue Oct 1, 2023 · 4 comments
Closed

Relative font-size support #212

andriytyurnikov opened this issue Oct 1, 2023 · 4 comments

Comments

@andriytyurnikov
Copy link
Contributor

I am exploring some approaches to responisve typography, and I am trying to use tricks like

.rescale-from-rem {
  font-size: calc(100% / 1.428);
}

.autoscaled-base {
  font-size: calc(1rem / 4 * 8);
}

Which results in

--font-size-px: NaN

I am not sure, what is going on here. Is implementation somehow reliant on pixel values?

@andriytyurnikov
Copy link
Contributor Author

Ok, I gave it more thought...
Just thinking out loud - comments are totally welcome:

  1. Solution we rely on in general - needs line height to be known.
  2. Current implementation performs some transformations during compile-time.
  3. Current implementation assumes single rem value (known during compile-time)

Therefore using current implementation with responsive rem won't be possible.

In order to implement responsive rem one would need to not rely on compile-time knowledge of rem and line-height, but current line-height value would have to be injected into context of CSS calc() anyway.

Conceptually it would look like:

font-size: 
  calc(
    1rem, 
    var(--rem-relative-font-size), 
    var(--rem-relative-line-height), 
    var(--font-metrics)
);

To achieve that one would have to alter(or bring his own) line-height utility classes, which would set --rem-relative-line-height, and his own --rem-relative-font-size and --rem-relative-font-metrics utility classes, and to express value of font-size as a dynamic calc()

@andriytyurnikov
Copy link
Contributor Author

Related to seek-oss/capsize#121

@andriytyurnikov
Copy link
Contributor Author

Ok, I've put some work into it, and here it is: CSS calc doesn't support division operation on unit values: calc(2rem / 1rem) doesn't work, therefore deriving ratios in CSS is problematic.

@andriytyurnikov
Copy link
Contributor Author

CSS-only rem solution is here: https://jsbin.com/danobedoye/11/edit?html,css,output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant