简体   繁体   English

网页字体渲染

[英]Font rendering for web pages

I always run into the same problem when creating web pages. 创建网页时,我总是遇到相同的问题。 When I add a font that is larger then about 16-18px it looks terrible. 当我添加一个较大的字体,然后大约16-18px时,它看起来很糟糕。 Its jagged, and pixelated. 其参差不齐,像素化。 I have tried using different fonts and weights, however I haven't had much luck there. 我尝试使用不同的字体和粗细,但是在那里我没有很多运气。

Note: Its only in windows that it is like this. 注意:仅在Windows中是这样的。 Mainly in Opera and FF also in IE7 but not quite as bad. 主要出现在Opera和FF中,也出现在IE7中,但还不算差。 In Linux the font looks good. 在Linux中,字体看起来不错。 I haven't looked at a Mac. 我没有看过Mac。

What do you guys do to fix this? 你们怎么解决这个问题? if anything. 如果有什么。 I noticed that the titles here on SO are also pretty jagged but they are just small enough not to look bad. 我注意到,SO上的标题也有些参差不齐,但它们足够小,不会显得很糟糕。

There is nothing you can do to force the user to change the way that their operating system renders fonts. 您无法执行任何强制用户更改其操作系统呈现字体的方式的操作。 If it is that big a deal to you then you can replace the large headings with images, this allows you to control exactly how the font is rendered (and ensures that the heading looks exactly as you wish, even if the user doesnt have your suggested font installed). 如果这对您来说很重要,则可以用图像替换大标题,这使您可以精确控制字体的呈现方式(并确保标题看起来完全符合您的期望,即使用户没有您的建议也是如此)字体安装)。

If you do this make sure that you provide an alternative text representation for those who do not see images. 如果这样做,请确保为看不见图像的人提供替代的文本表示形式。 I tend to use CSS to show a background image, and hide the contents of the heading. 我倾向于使用CSS来显示背景图像,并隐藏标题的内容。 Like this. 像这样。

<style>
    h1
    {
        height: 32px;
        width: 100px;
        background: url("path/to/image")
    }

    h1 span
    {
        display: none;
    }
</style>

<h1>
    <span>
       Heading Text
    <span>
</h1>

To be honest this does seem like overkill if it is on all large text. 老实说,如果在所有大文本上使用,这似乎都太过分了。 And be aware that it will increase the amount of data that your clients need to download. 并且请注意,这将增加客户端需要下载的数据量。 However for a large heading this method can lead to something that looks nicer than OS rendered text. 但是,对于较大的标题,此方法可能会导致看起来比OS呈现的文本更好的东西。

On Windows, enabling ClearType will solve this. 在Windows上,启用ClearType将解决此问题。 However, you can't force users to use it. 但是,您不能强迫用户使用它。 It's not a browser issue; 这不是浏览器问题; it's the operating system's font smoothing method. 这是操作系统的字体平滑方法。

启用抗锯齿功能可以解决显示问题。

除了抗锯齿之外,请尝试启用清除类型。

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

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