简体   繁体   English

在CSS中使用多种字体的原因

[英]Reason for using multiple fonts in CSS

What is the exact reason behind using multiple fonts in the CSS? 在CSS中使用多种字体的确切原因是什么? Is it do with different browsers? 是否与其他浏览器一起使用? Its something I've always just ignored in CSS but I'd like to understand the reason behind doing this now. 我一直在CSS中一直忽略它,但是我想了解现在这样做的原因。

body {
      font: normal normal 12px Arial, Tahoma, Helvetica, FreeSans, sans-serif;
     }

The reason is mostly because of fallback. 原因主要是由于回退。

If the user doesn't have a specific font installed it will take the next in the list. 如果用户未安装特定字体,它将使用列表中的下一个字体。

Nowadays this is usually not necessary, since everyone has the basic fonts installed and if not you can tell them to download a font file. 如今,通常不必这样做,因为每个人都已安装了基本字体,如果没有,您可以告诉他们下载字体文件。

In older browsers, there was no way to tell whether a specific font was installed and you couldn't include a custom font, so this was used to provide a fallback mechanism. 在较旧的浏览器中,无法判断是否已安装特定字体,并且无法包含自定义字体,因此该方法用于提供后备机制。

Another reason is that fonts on Mac and Windows are often different (they may be similar looking but have a different name). 另一个原因是Mac和Windows上的字体通常不同(它们的外观可能相似,但名称不同)。

The reason for using multiple font families is because some operating systems don't have some fonts preinstalled, and when the css doesnt find that font, it searches for the next one and so on. 使用多个字体系列的原因是因为某些操作系统未预安装某些字体,并且当CSS没有找到该字体时,它将搜索下一个字体,依此类推。

Helvetica for example doesn't come (as far as I know) shipped with OS X, so the CSS will look for the FreeSans font, and so on. 例如,据我所知,Helvetica并不随OS X一起提供,因此CSS将查找FreeSans字体,依此类推。

Multiple fonts are used in that example you posted to keep a sense of consistency for the website. 在您发布的该示例中使用了多种字体,以保持网站的一致性。 You wouldn't want to use Times New Roman and then use the "default" Comic Sans if the CSS doesn't find Times New Roman Installed. 如果CSS找不到安装的Times New Roman,则您不想使用Times New Roman,然后使用“默认” Comic Sans。

In technical terms it's called "Fallback" and you can find a more detailed explanation here: http://www.w3schools.com/cssref/pr_font_font-family.asp 用技术术语来说,它叫做“ Fallback”,您可以在这里找到更详细的解释: http : //www.w3schools.com/cssref/pr_font_font-family.asp

The fonts in the list you've shown ( Arial, Tahoma, Helvetica, FreeSans, sans-serif ) are implemented in that order so, if Arial is available, use it, if not, use Tahoma, etc. 您显示的列表中的字体(Arial,Tahoma,Helvetica,FreeSans,sans-serif)是按该顺序实现的,因此,如果Arial可用,请使用它,否则请使用Tahoma等。

The reasoning behind this is you put your prefered font first and, if the end user doesn't have that font installed on their machine then the next one is tried and so on. 这背后的原因是,您将首选字体放在首位,如果最终用户的计算机上未安装该字体,则尝试使用下一个字体,依此类推。 Generally, the last fonts in the list are so 'standard' that all users will have them ( sans-serif, serif, etc. ) - basically says use a font that is Sans-serif. 通常,列表中的最后一种字体是如此“标准”,以至于所有用户都会使用它们(sans-serif,serif等)-基本上说使用的字体是Sans-serif。

A font declaration might look like this: 字体声明可能如下所示:

font-family: "my weird font", "my alternative font", Arial, sans-serif;

SO, if the first two weren't available, 'Arial' would be used - which is generally known as a web-safe font as it ships with the basic insatalls of the vast majority of operating systems. 因此,如果前两个不可用,将使用'Arial'-通常被称为Web安全字体,因为它附带了绝大多数操作系统的基本安装程序。

It's fallback. 是后备。 If the browser don't find the first font, it looks for the next and etc. In you case it will look for Arial and if it finds it it will use it, if not it looks for Tahoma and so on 如果浏览器没有找到第一个字体,它将寻找下一个字体,依此类推。在这种情况下,它将寻找Arial ,如果找到它,它将使用它,否则,它将寻找Tahoma ,依此类推。

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

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