+ 1

can I make a custom function in css file just like calc() (ik calc is there by default)??

I want to make a custom function of pxtoem in css.So that I can simply write width: pxtoem(250) and it will be automatically converted to em ........(just like calc works in css)

16th Mar 2021, 3:07 PM
[ ]
[     ] - avatar
3 Answers
+ 3
no, you cannot: css is not a programing language, even if some rare built-in function are available in certain circumstances... however, convert px to em is not as obvious as you could think, because px are fixed units, while em are relative units: that means you need to refresh value each time element get another text size value (imagine now that element have a text-size value defined as relative too) ^^
16th Mar 2021, 3:24 PM
visph
visph - avatar
+ 2
You can use something like sass https://sass-lang.com/
16th Mar 2021, 5:19 PM
Jamal Saied
Jamal Saied - avatar
+ 1
visph Jamal thanks
16th Mar 2021, 6:06 PM
[ ]
[     ] - avatar