使用@font-face 使用多种自定义字体?
我确信我错过了一些非常直接的东西。一直使用带有普通字体的单个自定义字体:
@font-face {
font-family: CustomFont;
src: url('CustomFont.ttf');
}
当我使用它时一切正常,但如果我想添加另一个自定义字体我该怎么办?我尝试过用逗号分隔下一个字体或添加整个其他字体,但无法使第二种字体工作。
I'm sure I'm missing something really straight forward. Been using a single custom font with normal font face:
@font-face {
font-family: CustomFont;
src: url('CustomFont.ttf');
}
All works fine when I use it but if I want to add another custom font what do I do? I've tried separating by comma the next one or adding a whole other font face but can't get the second font working.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我在我的css文件中使用这个方法
I use this method in my css file
如果您遇到字体工作问题,我过去也遇到过这种情况,我发现的问题是 font-family: 名称。这必须与实际给出的字体名称相匹配。
我发现找到这个问题的最简单方法是安装字体并查看给出的显示名称。
例如,我在一个项目中使用了 Gill Sans,但实际的字体名为 Gill Sans MT。正确的间距和大写字母也很重要。
希望有帮助。
If you are having a problem with the font working I have also had this in the past and the issue I found was down to the font-family: name. This had to match what font name was actually given.
The easiest way I found to find this out was to install the font and see what display name is given.
For example, I was using Gill Sans on one project, but the actual font was called Gill Sans MT. Spacing and capitlisation was also important to get right.
Hope that helps.
查看fontsquirrel。他们有一个网络字体生成器,它还会为您的字体生成合适的样式表(查找“@font-face kit”)。该样式表可以包含在您自己的样式表中,也可以将其用作模板。
Check out fontsquirrel. They have a web font generator, which will also spit out a suitable stylesheet for your font (look for "@font-face kit"). This stylesheet can be included in your own, or you can use it as a template.
您可以非常轻松地使用多种字体。下面是我过去如何使用它的示例:
值得注意的是,字体在不同的浏览器中可能会很有趣。早期浏览器上的字体可以使用,但您需要使用 eot 文件而不是 ttf。
这就是为什么我将字体包含在 html 文件的头部,因为然后我可以使用条件 IE 标签来相应地使用 eot 或 ttf 文件。
如果您需要为此目的将 ttf 转换为 eot,有一个出色的网站可以免费在线执行此操作,可以在 http://ttf2eot.sebastiankippe.com/。
希望有帮助。
You can use multiple font faces quite easily. Below is an example of how I used it in the past:
It is worth noting that fonts can be funny across different Browsers. Font face on earlier browsers works, but you need to use eot files instead of ttf.
That is why I include my fonts in the head of the html file as I can then use conditional IE tags to use eot or ttf files accordingly.
If you need to convert ttf to eot for this purpose there is a brilliant website you can do this for free online, which can be found at http://ttf2eot.sebastiankippe.com/.
Hope that helps.
您只需添加另一个
@font-face
规则:如果您的第二种字体仍然无法工作,请确保您正确拼写了它的字体名称和文件名,您的浏览器缓存正常运行,您的操作系统不会乱用同名的字体等。
You simply add another
@font-face
rule:If your second font still doesn't work, make sure you're spelling its typeface name and its file name correctly, your browser caches are behaving, your OS isn't messing around with a font of the same name, etc.