问题描述:

Consider the following example: (live demo here)

HTML:

<div>Hello World</div>

CSS:

div {

font-family: monospace;

font-size: 1em;

}

JS:

$(function() {

alert($("div").css("font-size"));

});

In Firefox, the font size is 16px, while in IE8 the font size is 13px.

Why ?

(I tried to change the font-family to Arial, and both Firefox and IE8 say 16px.)

网友答案:

Each browser is a different product by a different company, they program their product differently, and font size is one of them. From this link, 1 em is equal to the current font size, which maybe different for different browsers, also user can change it, i have changed the text size to largest in IE, and the font size is now 21.33 px.

Using em means it is dependent on a lot of things, use %age for consistency.

1 em will be different for different browsers (depending on their default or of user has changed it). For example you said IE has font size of 13 px and firefox has 16 px, when i checked, firefox had 13 px and IE has 16 px, which was changed to 21.33 px when i changed the text size to largest (view -> text size)

网友答案:

Because em is a relative unit. An em is equal to the current font-size. If the font-size of the document is 16pt, 1 em is equal to 16pt.

MSIE seems to think that monospace doesn't need to be as big as Arial (in pixels) to be readable. For example, 12pt Times New Roman is about a big as 10pt Arial.

If you want fixed font sizes, use font-size: 16pt.

网友答案:

Because its an implementation choice. For instance, firefox has a configuration option to set the default font face and sizes for Sans, Serif and Monospace.

相关阅读:
Top