As you know em is a relative font measurement where one em is equal to the height of the letter "M" in the default font size. An advantage in using it is because you will be able to resize the text.
But how can i get default font size of current environment (in pixels) by using JavaScript or JQuery ?
regards,
There are a couple of situations this can be useful-
function getDefaultFontSize(pa){
pa= pa || document.body;
var who= document.createElement('div');
who.style.cssText='display:inline-block; padding:0; line-height:1; position:absolute; visibility:hidden; font-size:1em';
who.appendChild(document.createTextNode('M'));
pa.appendChild(who);
var fs= [who.offsetWidth, who.offsetHeight];
pa.removeChild(who);
return fs;
}
alert(getDefaultFontSize())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With