比较 Chrome 和 Firefox 的字体大小问题
我建立了一个网站,问题是,chrome 显示的 font-size 1px
比 Firefox 大。我尝试了几种方法来匹配字体大小,以 px 为单位指定,以 % 为单位将正文设置为 100%,然后将元素设置为 0.875em
。这些都不起作用。它仍然在 Chrome 中显示多 1 像素。
这是我用于字体大小的代码:
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;
}
#geral 包裹整个网站并且 CSS 上没有其他字体大小声明,可以在我发布的链接中查看源代码。
我想知道是否有办法解决这个问题,或者我是否必须为每个浏览器指定不同的字体大小?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我建议您使用 CSS 重置,例如 YUI 中的重置。它将使您的页面在所有浏览器中更加一致,包括字体渲染。它与 IE 和其他浏览器有最大的区别,但它消除了各种不一致的情况。
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 在这个日期,我自己最近刚刚了解到,良好的 CSS 编码实践是仅为 HTML 或 BODY 元素定义绝对字体大小,并相对地定义所有其他字体大小,即根据此大小(即使用
em
或%
)。如果您这样做,您只需从其他浏览器(Gecko、IE 等)中挑选出 webkit 浏览器(Chrome、Safari)即可。因此,例如,您可能已在样式表中定义,
然后在样式表的底部,您可以包含此内容
(另请参阅Chrome 条件注释)
这对我有用。但一个副作用是也会重新调整相对大小的任何非文本元素,这可能是理想的,也可能不是。
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,
Then at the bottom of the stylesheet, you can include this
(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.
在这里工作正常:
Chrome 9.0:
Firefox 4.0 beta 10:
Works fine here:
Chrome 9.0:
Firefox 4.0 beta 10:
em
是可缩放的,而px
则不可缩放。将字体设置为定义的px
大小,应该没问题。em
在某些情况下可能是理想的,但如果您担心 1px,那么您应该设置严格的像素大小。编辑:只需重读,我发现您已经尝试将高度设置为像素。没有任何线索,因为我没有在这里安装 Chrome 来测试。 :(
em
is scalable andpx
is not. Set the font to a definedpx
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. :(
如果您有要打印的网页,
添加 css
请在 css 文件中
,这对我有用
if you have web page to print then
add css
in css file
this works for me
我也遇到过这个问题,我决定尽可能使用 font-size:small (或 x-small 等)。这为您提供了基本的可缩放字体大小范围,而无需寻找繁琐的 css 或搞乱 JS。它适用于 IE、FF 和 Chrome。
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.
当我使用这个 css 时,我在 Firefox 和 Chrome 之间的渲染方面获得了足够好的相似性(它可以工作,因为 Firefox 尚未实现“缩放”):
但它仍然不是像素完美的。
请注意,我在任何地方都使用“rem”单位而不是“px”单位,因为当我在页面上使用多种字体时,效果更好。
请注意,我已将 Windows 显示分辨率设置为 150%,以弥补我视力不佳的问题。当我将其设置回100%时,尺寸不同的问题仍然存在。所以这不是问题。
我确信没有标准规定页面在不同浏览器上必须看起来相同,但使用“缩放”似乎在这方面有所帮助。
除非这个比例因子问题是由于我的计算机配置错误造成的。
I'm getting a good enough similarity in rendering between Firefox and Chrome when I use this css (it works because Firefox does not yet implement 'zoom'):
But it still isn't pixel perfect.
Note that I use 'rem' units instead of 'px' units everywhere, as this works better when I use more than one font on a page.
Note that I've set Windows display resolution to 150% to compensate for my poor vision. When I set it back to 100%, the problem of different sizes remains. So this isn't the issue.
I'm sure there is no standard that says that pages must look the same on different browsers, but using 'zoom' seems to help in this regard.
Unless this scale factor problem is due to a misconfiguration on my computer.