Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  12] [ 7]  / answers: 1 / hits: 33996  / 15 Years ago, fri, september 18, 2009, 12:00:00

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,


More From » jquery

 Answers
15

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())


[#98666] Tuesday, September 15, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
stacie

Total Points: 476
Total Questions: 92
Total Answers: 102

Location: Bosnia and Herzegovina
Member since Tue, Mar 29, 2022
2 Years ago
stacie questions
Fri, Jun 26, 20, 00:00, 4 Years ago
Thu, Jan 23, 20, 00:00, 4 Years ago
Fri, Aug 30, 19, 00:00, 5 Years ago
Fri, Aug 2, 19, 00:00, 5 Years ago
;