+ 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)
3 ответов
+ 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) ^^
+ 2
You can use something like sass
https://sass-lang.com/