Why are the font sizes different

2019-05-15 16:40发布

问题:

I've got the following html and css
In Firefox the computed font size is 16.66667px
In Chrome the computed font size is 13px

Needless to say there is a good bit of difference in these two sizes, one is too small to read, one is nicely sized. I guess one way to work around it is to set the font size to 16.67px but why is this the case.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
  <title>My first styled page</title>
  <style type="text/css">
    body {
        font-family: Arial, sans-serif;
        font-size: 10pt;
    }
  </style>
</head>
<body>

    This is some text.
</body>
</html>

All my measurements come from inspect element (using firebug in firefox).

回答1:

The font sizes are different because the browser programmers make different assumptions about the normal user's system.

There's nothing wrong with that, and this is also why you should not use px to set the font size. On a computer with a high-resolution screen, your font will be too small. Certainly 10px will be unreadable on many people's computers.

I recommend How to Size Text in CSS for a good overview of your choices.



回答2:

pt is a unit used for print and is not reliable for cross browser screen sizing. Try using another unit like px, em or a straight percentage.



回答3:

Try setting the font size in PX like font-size:10px