Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert px into % like we convert px to em for Font-Size?

Tags:

css

I was using em but facing problem in nested items so I decided to use % as yui suggesting.

To change the size of a font, always use percentages as the units because they render more consistently than ems, and because they allow user-initiated resizing (unlike pixels).

How to convert px into %? like this is for Px to em http://pxtoem.com/

Edit

I found this example is very good but it's only till 24px.

http://yuilibrary.com/yui/docs/cssfonts/cssfonts-size.html

How to calculate size in % for each size in px. As a example case, according to this table what will be size in % for 45px

like image 939
Jitendra Vyas Avatar asked Jan 19 '23 20:01

Jitendra Vyas


1 Answers

There are already 2 answers posted, however, they're not correct. Every CSS property that accepts percentage length, defines how these values are being computed. In the terms of font-size, this is what CSS 2.1 says:

Percentages: refer to inherited font size

It will never depend on window size or so.

How to convert pixels into percents: in most cases, 16px is the default value for font-size - this is 100%. 45px will thus be 100% * 45px / 16px = 281.25%.

like image 107
duri Avatar answered Jan 22 '23 21:01

duri