How can i get default font size in pixels by using JavaScript or JQuery?

前端 未结 9 1481
Happy的楠姐
Happy的楠姐 2021-02-04 09:07

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 a

9条回答
  •  渐次进展
    2021-02-04 09:43

    I think this is what you're looking for:

    function getDefaultFontSize () {
    // this will return the default* value assigned to the style: fontSize
    defsize=(document.body.style.fontSize)
    alert('The default font size of your browser is: "' + defsize + '"');
    }
    

    *If body has a different fontSize decleration anywhere else in the code (perhaps in some css) the function will return that value. For example:

    
    
    

    The above will return a fontSize value of 20px.


    Fully tested and works for me (chrome 22.0.1229.94 m and firefox 13.01).

提交回复
热议问题