简体   繁体   English

Windows和Mac OS X之间的字体大小

[英]Font-Size between Windows and Mac OS X

I work on a project and i want to know Why there is a difference in font size(width) on web between Windows and Mac OS X. I found that all the browsers on Mac will have the same size, but in the Windows it differ from browser to anther. 我正在做一个项目,我想知道为什么Windows和Mac OS X之间的Web字体大小(宽度)有所不同。我发现Mac上的所有浏览器都具有相同的大小,但是在Windows中却不同从浏览器到花药。 i frustrated and wait to here from you. 我很沮丧,等你到这里来。 My question now why there is a difference in width between them? 现在我的问题是为什么它们之间的宽度不同?

There are many possible reasons: 有许多可能的原因:

  1. Different fonts. 不同的字体。 Very few Mac fonts are identical to fonts on Windows. 很少有Mac字体与Windows上的字体相同。 (It's not clear if you're expecting the Windows results to match the Mac results or just for them to be consistent on Windows.) (尚不清楚您是否期望Windows的结果与Mac的结果相匹配,还是只是希望它们在Windows上保持一致。)

  2. Different default sizes. 不同的默认大小。 Most browsers have defaults for font and size, and they may not all be the same. 大多数浏览器都有字体和大小的默认值,并且它们可能并不完全相同。

  3. Different interpretations of font size. 字体大小的不同解释。 When you say you want (for example) a 10-point font, it's not entirely well-defined what that means. 当您说想要(例如)10点字体时,这并不是完全清楚的含义。 There are true points (1/72.27 inch) but more commonly computer points (1/72 inch). 有真实的点(1 / 72.27英寸),但更常见的是计算机的点(1/72英寸)。 Do you want the character cell height? 您是否想要字符单元格高度? With or without internal leading? 有无内部领导? Or did you mean the actual character height or merely the font's ascent? 还是您指的是实际字符高度,还是仅指字体的上升? Different browsers may choose to interpret sizes differently. 不同的浏览器可能会选择不同的解释大小。

  4. Different resolutions. 不同的分辨率。 Browsers may handle different screen resolutions differently. 浏览器可能会以不同方式处理不同的屏幕分辨率。 Windows has a concept of a "logical inch", which is typically larger than a true inch on displays. Windows具有“逻辑英寸”的概念,通常比显示器上的实际英寸大。 But how much larger is customizable by the user. 但是用户可以自定义更大的尺寸。 Some browsers may ignore the logical inch and use the actual DPI of the device (or at least what they think the DPI is--the OS may not actually know). 一些浏览器可能会忽略逻辑英寸,而使用设备的实际DPI(或至少他们认为的DPI是什么-操作系统可能实际上不知道)。

  5. Different rendering technologies. 不同的渲染技术。 Whether you use hinting, antialiasing, subpixel rendering (eg, ClearType), or some combination of these can slightly affect the width of text (even if everyone agrees on the exact font and the exact vertical size). 无论您使用提示,抗锯齿,子像素渲染(例如,ClearType)还是这些的某种组合,都会稍微影响文本的宽度(即使每个人都同意确切的字体和确切的垂直大小)。

  6. Different scales. 不同的规模。 Most browsers provide a scaling feature, and it's possible that they aren't defaulting to the same value on different browsers. 大多数浏览器都提供缩放功能,并且在不同的浏览器上可能未默认使用相同的值。 Also note that as you change the scale, the text width often won't scale linearly (see #5). 另请注意,更改比例时,文本宽度通常不会线性缩放(请参阅#5)。

Any one of these issues can lead to differences in text width (which can cascade into different word wrapping choices), making pages look different from browser to browser and machine to machine. 这些问题中的任何一个都可能导致文本宽度的差异(这可能会层叠为不同的自动换行选项),从而使页面在浏览器之间和浏览器之间以及机器与机器之间看起来都不同。 In many cases, you might have a combination of these issues thwarting consistency. 在许多情况下,您可能会合并使用这些问题来破坏一致性。

The solution is to design layouts to be flexible. 解决方案是设计布局灵活。 Don't create implicit dependencies on font sizes by hardcoding things (like the size of a ) and expect the text to always fit. 不要通过对事物(例如的大小)进行硬编码来创建对字体大小的隐式依赖关系,并期望文本始终适合。 Generally, choose sizes relative to the size of the text, and be prepared for variation in the actual text size. 通常,选择相对于文本大小的大小,并为实际文本大小的变化做好准备。

There's a difference because there is no standard that mandates the text size for web page rendering. 两者之间存在差异,因为没有标准规定网页渲染的文本大小。 And so browser vendors are free to render text at whatever size they wish. 因此,浏览器供应商可以自由选择所需大小的文本。

I've run into this problem working on HTML ads that need to render consistently. 我在处理需要持续呈现的HTML广告时遇到了这个问题。 In such situations, elements even a few pixels off can make a design look amateur. 在这种情况下,即使只有几个像素的元素也会使设计看起来很业余。

One way to get more accurate cross-platform results is to specify pixel values rather than points or ems. 获得更准确的跨平台结果的一种方法是指定像素值,而不是点或em。 Such text will render at the same size regardless of device resolution, and will still scale properly when zooming in and out. 无论设备分辨率如何,此类文本都将以相同的大小呈现,并且在放大和缩小时仍将正确缩放。 Even on a Retina/HD display, since a CSS pixel isn't necessarily the same as a device pixel. 即使在Retina / HD显示器上,由于CSS像素不一定与设备像素相同。

In addition, forcing the use of either a web font or a very common font, along with explicitly setting the anti-aliasing method, will get you even closer to pixel-perfect results. 此外,强制使用网络字体或非常常用的字体,以及显式设置抗锯齿方法,将使您更加接近像素完美的结果。 I've found the code below to render nearly identically regardless of environment. 我发现下面的代码无论环境如何都几乎相同。

html, body {
    font-family: Arial, sans-serif;
    font-size: 13px;
    -webkit-font-smoothing: antialiased;
    font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM