@font-face:仅使用一种具有不同字体粗细的字体系列?
我在我正在开发的网站上使用“Open Sans”字体。现在我正在使用 Google Web Fonts 来加载它,但当它随机开始使用粗体 700 版本而不是正常的 400 时,我意识到这不是最可靠的方式(您可以在 http://www.google.com/webfonts/specimen/Open+Sans)。无论如何,我想更改为 @font-face 并自己托管字体,但是有些东西我不明白。借助 Google Web Fonts,我可以对所有不同的粗细使用相同的字体系列,因此我只需对 body 元素使用以下规则:
font-family:'Open Sans', sans-serif;
特定元素上的不同字体粗细取决于它是否需要浅色、正常或粗体。但是使用 Font Squirrel 生成的 @font-faces 时,似乎您必须为每个不同的粗细指定不同的字体系列,例如“OpenSansLight”、“OpenSansRegular”等。这是为什么呢?有没有办法改变它,这样我就不必改变我的整个CSS?
谢谢。
I use the font "Open Sans" for a website I'm working on. Right now I'm using Google Web Fonts to load it but I realized it's not the most reliable way when it randomly began to use the bold 700 version instead of normal 400 (you can check by yourself at http://www.google.com/webfonts/specimen/Open+Sans). Anyways, I would like to change to @font-face and host the font myself, however there's something I don't understand. With Google Web Fonts I'm able to use the same font-family for all the different weights, so I just have this rule to the body element:
font-family:'Open Sans', sans-serif;
and different font-weights on specific elements depending on whether it needs to be light, normal, or bold. But with @font-faces generated by Font Squirrel, it seems you have to specify a different font-family for each different weight, such as 'OpenSansLight', 'OpenSansRegular', etc. Why is that? And is there a way to change that so I don't have to change my whole CSS?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当我们通过 cdn 加载 google 字体时,它基本上会加载所有选定的字体选项(更亮、更粗、更粗)
如您所见,“source code pro”字体的所有字体粗细均已加载。
当你从谷歌下载字体时。它为所有选定的选项提供不同的文件。这可能会减少加载不需要的字体(如果谷歌制作单一字体,则与该字体相关的所有字体粗细选项都必须放入单个文件中)。这会导致文件大小更大。
这就是为什么最好单独加载文件的原因。但不是以“OpenSans Regular”名称加载它,而是以“OpenSans Bold”名称加载。您可以使用“Open Sans”并分配不同的字体粗细。 (但按各自的字体粗细加载各自的文件)。
When we load google fonts via cdn it basically loads all the selected font options (lighter, bolder, extra bold)
As you can see all the font-weight for "source code pro" font is loaded.
When you download a font from google. It gives different files for all selected options. This is may be reduce unwanted fonts being loaded (if google makes a single font, then all font-weight options related to the font have to be put in the single file). This causes bigger file size.
This is why it is good to load the files individually. But instead of loading it under names 'OpenSans Regular', 'OpenSans Bold' for eg. you can use 'Open Sans' and assign different font-weights. (but load respective files on respective font-weights).