Why is IE9/Firefox showing a different font size i

2019-02-21 10:18发布

I'm programming the CSS of a site, and realized that the Internet Explorer 9 is showing different font size in relation to other browsers (Firefox, Chrome, Safari, IE7 and IE8).

I've tried using some RESETS, and I am specifying the font in px, but IE9 still shows the difference in font size.

I've tried using font-size in pt, in, percentage, but had no success.

I changed the font before (Georgia, Times New Roman, Verdana). Some of them are shown larger, others are smaller in IE9.

I checked the zoom settings and text size in IE. They are 100% and medium respectively.

To illustrate, I created a simple HTML and CSS as you can see the code below. How to solve this problem? Thanks!

The problem:

enter image description here

Code:

HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="style.css" />
    <title>Untitled Document</title>
</head>
<body>
    <p>
    AAAAA BBBBB CCCCC DDDDD EEEEE FFFFF GGGGG HHHHH IIIII JJJJJ KKKKK LLLLL MMMMM NNNNNN OOOOO PPPPP QQQQQ
    </p>
</body>
</html>

CSS

/* RESET */

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
    display: block;
}
body {
    line-height: 1;
}
ol, ul {
    list-style: none;
}
blockquote, q {
    quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
    content: '';
    content: none;
}
table {
    border-collapse: collapse;
    border-spacing: 0;
}

/* END OF RESET */

body {
    background-image:url(GreenLine.png);
    background-repeat:no-repeat;
    font-family:"Courier New", Courier, monospace;
    font-size:12px;
}

3条回答
相关推荐>>
2楼-- · 2019-02-21 10:35

Try to set the body{font-size:medium; line-height:1em;} where the font-size will be of 16px now and use percent on p tag to increase or decrease the font-size. To be sure of limit the width of the p tag.

P{max-width:40%; font-size:86%; line-height:1.2em;}
查看更多
贪生不怕死
3楼-- · 2019-02-21 10:42

Two possible things, both untested:

  1. try changing the doctype to something other than xhtml transitional. See if the HTML5 doctype renders it better. <!DOCTYPE html>

  2. try using only font-family: monospace; to see if it is a font issue.

EDIT

If those do not work and you cannot find a solution, you might want to serve IE9 a different font-size using conditional comments.

查看更多
老娘就宠你
4楼-- · 2019-02-21 10:50

IE9 uses DirectWrite to render text, and other browsers do not (except for Firefox 4+).

That is the reason for the slightly different size of the text between the two browsers.

There is no way to make the text the same size.

Read this: http://www.basschouten.com/blog1.php/font-rendering-gdi-versus-directwrite

And this, particularly the "Hinting and spacing differences" section: http://blog.mozilla.com/nattokirai/2011/08/11/directwrite-text-rendering-in-firefox-6/

查看更多
登录 后发表回答