Font-size issues comparing chrome and Firefox
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?
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.
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.
<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>
Works fine here:
Chrome 9.0:
Firefox 4.0 beta 10:
em
is scalable and px
is not. Set the font to a defined px
size and you should be ok. em
can be desirable in certain circumstances, but if you are worried about 1px then you should set strict pixel sizes.
EDIT: Just reread and I see you have tried setting the height as pixels already. Don't have a clue then as I don't have Chrome installed here to test. :(