Font-size issues comparing chrome and Firefox

70,359

Solution 1

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.

Solution 2

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.

Solution 3

<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>

Solution 4

Works fine here:

Chrome 9.0: enter image description here

Firefox 4.0 beta 10: enter image description here

Solution 5

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

Share:
70,359
Iberê
Author by

Iberê

Software Analyst, BS in Information Systems, working for the IT Industry for more than 5 years creating software using Python, Java, PHP and Javascript. Working with MySql, SQL Server, Git, Jenkins, Gradle, Memcache, Web Services, Elasticsearch/Lucene, Amazon AWS, Bootstrap, Jinja, New Relic and a variety of Frameworks.

Updated on March 16, 2020

Comments

  • Iberê
    Iberê over 4 years

    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 the body to 100% and then the elements to 0.875em. None of those work. It stills display 1 pixel greater in chrome.

    This is the code I'm using for font-sizes:

    body {
      font-size: 100%;
    }
    * {
      margin:0;
      padding:0; 
      text-decoration: none; 
      font-family:helvetica, arial, sans-serif;
    }
    #geral {
      width:1000px; 
      margin:0 auto; 
      position:relative; 
      font-size:0.875em;
    }
    

    Where the #geral wraps the entire site and there is no other font-size statement on the CSS, the source can be viewed in the link I posted.

    I wonder if there is a way to fix that or if I'll have to specify different font-sizes for each browser?