Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

CSS variables is not working with calculation

I got some variables defined in root. However, when I use calc to calculate font size, I don’t know why it’s not working, what did I do wrong?

:root {
    --test-01: 20;
    --test-02: 120;
    --test-1: 1;
    --test-2: 3;
}

#test {
  font-size: clamp(var(--test-1)rem, calc(var(--test-1)rem + (var(--test-2) - var(--test-1)) * ((100vw - var(--test-01)rem) / (var(--test-02) - var(--test-01)))), var(--test-2)rem);
}
<p id="test">Testing...123</p>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can not write var(--test-1)rem, you either have to specify the unit in the var declaration --test-1: 1rem or multiply by 1rem calc(var(--test-1) * 1rem).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading