【发布时间】:2011-10-05 06:34:49
【问题描述】:
此测试图像显示了 Safari 与 Firefox(Mac OS X 10.6.7 的 Safari 5.0.5 和 Firefox 5.0.1)在文本框中的位置差异有多大。请注意,sans-serif 的“S”在 Firefox 而不是 Safari 中是如何与框的顶部对接的。差异似乎因所使用的字体而异,有些甚至是一致呈现的。
我读过people saying,这是因为font-size 和line-height 之间的舍入问题(并通过设置比大小更小的高度来解决),但我认为我的例子证明了无衬线/黑体在 Firefox 中始终对齐框的顶部。
在我看来,Safari 似乎比 Firefox 更正确,即文本通常更多地位于中间线附近。
有没有让它们更加一致的好方法?我的目标只是符合标准的浏览器。
- NB1:这与
vertical-align无关。 - NB2:我调查了similar problem in the past,但没有完全令人满意的结果。
我的测试代码:http://jsbin.com/omaboc
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<style type="text/css">
body {
font-size: 50px;
line-height: 1em;
}
div {
background: #b5e260;
margin-bottom: 5px;
}
</style>
</head>
<body>
<div style="font-family: sans-serif">Some text @ this box</div>
<div style="font-family: serif">Some text @ this box</div>
<div style="font-family: arial">Some text @ this box</div>
<div style="font-family: helvetica">Some text @ this box</div>
<div style="font-family: courier">Some text @ this box</div>
<div style="font-family: georgia">Some text @ this box</div>
</body>
</html>
【问题讨论】:
-
在 Windows 7 上不会发生同样的问题,请参阅:i.stack.imgur.com/xQmTe.gif
-
令人兴奋。剧情变厚了! +1 用于 GIF 动画 ;)
-
查看这条小狗的公认答案:stackoverflow.com/questions/7155174/…
-
这完全是垃圾,无法设计。我感觉到你的痛苦
-
我也遇到了同样的问题jsfiddle.net/y5ofqfn7/1firefox和safari的位置差是7px
标签: css html webkit mozilla vertical-alignment