Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert rem to px without reflow

I have some constant in rems, but rem itself isn't a constant (depends on media queries and vmin). For some perpoise I need this value in px.

Of course I can create a temporary div, set its size to that value in rem and getComputedStyle of it to get value in px. But I'd like to do that without causing a reflow by reading the computed style.

like image 957
Qwertiy Avatar asked Dec 23 '22 16:12

Qwertiy


1 Answers

A rem unit equal to the computed value of ‘font-size’ on the root element. (https://www.w3.org/TR/2013/CR-css3-values-20130730/#font-relative-lengths)

You can get that easily enough with 1 rem =

parseInt(getComputedStyle(document.documentElement).fontSize))
like image 156
Mark Avatar answered Dec 31 '22 12:12

Mark