如何将外部字体加载到 HTML 文档中? [英] How do I load external fonts into an HTML document?

查看:51
本文介绍了如何将外部字体加载到 HTML 文档中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将外部字体文件加载到 HTML 文档中.

How do I load external font files into an HTML document.

示例:使用 HTML CSS 和/或 JAVASCRIPT 使文本blah blah blah blah blah blah blah blah"成为同一目录中 TTF 文件的自定义字体

Example: Make the text "blah blah blah blah blah blah blah" a custom font from a TTF file in the same directory using HTML CSS and/or JAVASCRIPT

推荐答案

看看这个 A List Apart文章.相关的 CSS 是:

Take a look at this A List Apart article. The pertinent CSS is:

@font-face {
  font-family: "Kimberley";
  src: url(http://www.princexml.com/fonts/larabie/kimberle.ttf) format("truetype");
}
h1 { font-family: "Kimberley", sans-serif }

上述内容适用于 Chrome/Safari/FireFox.正如 Paul D. Waite 在评论中指出的那样,如果您将字体转换为 EOT 格式.

The above will work in Chrome/Safari/FireFox. As Paul D. Waite pointed out in the comments you can get it to work with IE if you convert the font to the EOT format.

好消息是,这在较旧的浏览器中似乎可以优雅地降级,因此只要您意识到并非所有用户都会看到相同字体的事实并对此感到满意,就可以安全使用.

The good news is that this seems to degrade gracefully in older browsers, so as long as you're aware and comfortable with the fact that not all users will see the same font, it's safe to use.

这篇关于如何将外部字体加载到 HTML 文档中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆