且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-01-21 20:24:29

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

  @ font-face {
font-family:Kimberley;
src:url(http://www.princexml.com/fonts/larabie/kimberle.ttf)格式(truetype);

h1 {font-family:Kimberley,sans-serif}



EOT格式。好消息是,这似乎在旧的浏览器中优雅地退化,所以只要你意识到并且舒适的事实,并不是所有的用户都会看到相同的字体,这是安全的使用。


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

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

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 }

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.