Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate REM for type?

Tags:

css

How do I convert PX into REM for my type? I've read Jonathan Snook's article about using REM, but he was using font-size:62.5%, which defaults to your font size to 10px (for easier calculating). How would I convert my PX units into REM if I was to use 100%, 75%, and so forth?

like image 963
alyus Avatar asked Jul 05 '12 21:07

alyus


People also ask

What is the value of 1 rem?

1rem therefore takes on the value which is given to the font-size of the root element. This means that 1 REM keeps the same value throughout your whole CSS code. If the root element's font size is not changed by the user this value is normally 16px .


2 Answers

Target Size / Base Size = Value

Since we can assume that browsers use 16px as default (after all, that's what Jonathan Snook did to assume that 62.5% is 10px), then your Base is 16. If you want 32px, then 32 / 16 = 2, want 40px then 40 / 16 = 2.5, want 24 then 24 / 16 = 1.5.

The same goes for 75%... Determine what 75% is (it's 12) and perform the same calculation. If you want 32px, then 32 / 12 = 2.666, want 40px then 40 / 12 = 3.333, want 24 then 24 / 12 = 2.

like image 179
nEx.Software Avatar answered Sep 19 '22 19:09

nEx.Software


if u just add this code to your style file

html {
  font-size: 62.5%;
}

it will convert 1 rem=10px. Now you will be working 10px base. So

body {
  font-size: 1.6 rem;
}

u will have font size 1.6*10=16 px.

like image 40
Yilmaz Avatar answered Sep 21 '22 19:09

Yilmaz