Font-size issues comparing chrome and Firefox

后端 未结 7 741
清酒与你
清酒与你 2020-11-27 06:07

I built a site and the problem is, chrome display font-size 1px bigger than Firefox. I tried several ways to match the font-size, specified it in px, in % set t

相关标签:
7条回答
  • 2020-11-27 06:14

    I suggest you use a CSS reset like the one from YUI. It will make your pages much more consistent across all browsers, including font rendering. It makes the biggest difference with IE and the other browsers, but it gets rid of all manner of inconsistencies.

    0 讨论(0)
  • 2020-11-27 06:17

    Works fine here:

    Chrome 9.0: enter image description here

    Firefox 4.0 beta 10: enter image description here

    0 讨论(0)
  • 2020-11-27 06:18
    <script>
    
         if(navigator.userAgent.indexOf("Chrome") != -1 ) 
        {
             var fontsize = "<style>body{font-size: 125%;}</style>";
        }
        else if(navigator.userAgent.indexOf("Opera") != -1 )
        {
             var fontsize = "<style>body{font-size: 100%;}</style>";
        }
        else if(navigator.userAgent.indexOf("Firefox") != -1 ) 
        {
             var fontsize = "<style>body{font-size: 100%;}</style>";
        }
        else if((navigator.userAgent.indexOf("MSIE") != -1 ) || (!!document.documentMode == true )) //IF IE > 10
        {
             var fontsize = "<style>body {font-size: 100%;}</style>";
        }  
        else 
        {
             var fontsize = "<style>body {font-size: 100%;}</style>";
        }
        </script>
    
    <script>document.writeln(fontsize);</script>
    
    0 讨论(0)
  • 2020-11-27 06:22

    if you have web page to print then

    add css

    <link rel="stylesheet" type="text/css" href="report.css" media="print" />
    

    in css file

    body {
        padding: 3px;
        margin: 0.5px;
        background-position: center;
        color: #000000;
        background: #ffffff;
        font-family: Arial;
        font-size: 13pt;
    }
    

    this works for me

    0 讨论(0)
  • 2020-11-27 06:22

    I too have had this problem and I've decided, where possible to go with font-size: small (or x-small etc). This gives you a basic range of scalable font sizes without having to look for fiddily css or messing around with JS. It works with IE, FF and Chrome.

    0 讨论(0)
  • 2020-11-27 06:24

    Fwiw at this date, I myself have just recently learned that good CSS-coding practice is to define absolute font-size only for the HTML or BODY element, and to define all other font-sizes relatively, that is, in terms of this size (i.e., using em or %).

    If you do that, you only need single out webkit browsers (Chrome, Safari) from the others (Gecko, IE, etc.). So, for example, you might have defined in your stylesheet,

    body {
      font-size: 16px;
    }
    

    Then at the bottom of the stylesheet, you can include this

    @media screen and (-webkit-min-device-pixel-ratio:0) { 
      Body {
        font-size: 20px;      
        }
    }
    

    (See also Chrome conditional comments)

    This works for me. But one side-effect is to also rescale any non-text elements that are sized relatively, and this may or may not be desirable.

    0 讨论(0)
提交回复
热议问题