Firefox 默认字体大小问题
灵活的布局使用 em 或 % 作为字体大小单位,常见的做法是使用 body 字体大小为 62.5%
但 Firefox 的默认字体是 14px,这导致布局比其他具有 16px 默认字体大小的布局更小
我们不能只修复 body font-size 为 10px,以便相对大小适用于每个浏览器。
Flexible layouts use ems or % as font-size units a common practice is to use body font-size as 62.5%
But Firefox's default font is 14px which results in smaller layout than others who have 16px default font size
Can't we fix just body font-size to 10px so that relative sizes works in every browser.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
另外,除了@Ray 的答案之外。
对于此类浏览器不一致的情况,请考虑使用重置样式表。
可以在此处找到一个好的。以及此处。
我将代码粘贴在这里以供参考。
Also, in addition to @Ray's answer..
For browser inconsitencies like these, consider using a reset stylesheet.
A good one can be found here. and here.
I am pasting the code here for sake of reference.
您在这里说了很多正确的话:
Ems 和百分比传统上是用于“可扩展”布局的单位。
CSS 中的“级联”包括浏览器自己的样式表。因此,每当您省略某些元素的样式属性时,它都会搜索级联,并从链末尾的浏览器样式表中获取这些缺失的属性。
如果您希望页面文本的像素完美字体处理在浏览器中看起来相同,则需要自己定义字体大小。在
body
元素上使用px
应该可以满足您的需求。我不知道为什么这仍然是一个问题。曾经有一段时间,有些人会避免使用px
,但现代浏览器可以很好地处理缩放,现在我怀疑这不再是一个问题了。You are saying a lot of the right things here:
Ems and percents have traditionally been the units to use for "scalable" layouts.
The "cascade" in CSS includes the browser's own style sheet. So whenever you omit a style property for some element, it searches through the cascade and will pick up these missing properties from the browser's style sheet at the end of a chain.
If you want pixel-perfect font handling for page text that looks the same across browsers, you will need to define a font-size yourself. Using
px
on thebody
element should give you what you want. I'm not aware of any reason why this is still an issue. There was a time when some people would avoidpx
but modern browsers handle zooming nicely now that I suspect it is much less of an issue than it was.