seedy wrote:


Sam Collett wrote:
How can I then convert the %/em value into pixels?

Short Answer : You can't really convert em to pixels as em is a relative
value.

Long Answer:
The default font size for browsers is 16px = 1em.  So you could make that
assumption and use 16px to calculate your pixel value, but if the user has
changed their browsers font size it could look wrong. Also, when font sizes are rendered in em, it could be inheriting from another element body{font-size:0.69em}
element{font-size:0.75em}
In this case, if you only looked at the em value for element (0,75em), again
your calculation would be wrong.
Percentages will work mostly in this same way.  There is another unit of
font measurement you may have to worry about called ex, but I am not to
familiar with how that works.

Sorry I don't have an answer, as a consolation prize here is a nifty tool
for em -> px calculations.
http://riddle.pl/emcalc/


Couldn't you add an element as direct child to the body, for which you define:

position: absolut;
visibility: hidden;
height: 1em;
font-size: 100% !important;

Then you can just poll the height of that element, e.g. the offsetHeight and get the current pixel value. That would even work if the default size has been changed.

And it would not only work for the body element, it should work whereever you append that element. The jqem plugin works in a similiar way and I think I have seen something like that somewhere else already, maybe in YUI.


--Klaus

Reply via email to