简体   繁体   English

为网站用户添加字体到HTML / CSS代码(跨浏览器)

[英]Adding fonts to HTML/CSS code for website users (cross-browser)

Say I have several .otf and .dfont font files that are used in PSD for web site design. 假设我有几个用于PSD网站设计的.otf和.dfont字体文件。 Now I need to add those fonts into the HTML/CSS code. 现在我需要将这些字体添加到HTML / CSS代码中。 I know @font feature of CSS3 which does that. 我知道CSS3的@font功能可以做到这一点。 But I am sure that it would not work for older browsers? 但我相信它对旧版浏览器不起作用? So what is the cross browser way of doing that? 那么跨浏览器的方式是什么呢?

Firstly, websites need not look alike in all the browsers ( http://dowebsitesneedtolookexactlythesameineverybrowser.com/ ). 首先,网站在所有浏览器中看起来都不一样( http://dowebsitesneedtolookexactlythesameineverybrowser.com/ )。 It is perfectly fine to not display these fonts in the older browsers. 在旧版浏览器中不显示这些字体是完全正常的。 Just provide a fallback as @ThiefMaster mentioned. 只是提供@ThiefMaster提到的后备。

In case , you insist on using the same fonts even for older browsers, you might have to rely on Cufon ( http://cufon.shoqolate.com ) for cross browser compatibility. 如果您坚持使用相同的字体,即使是旧浏览器,您可能不得不依赖Cufon( http://cufon.shoqolate.com )来实现跨浏览器兼容性。 Use a feature detection (using Modernizr ) and conditionally load the Cufon library. 使用特征检测(使用Modernizr )并有条件地加载Cufon库。 Be warned that using Cufon on body text would make the page load slower. 请注意,在正文上使用Cufon会使页面加载速度变慢。

PS: All IE versions support web font embedding. PS:所有IE版本都支持Web字体嵌入。

You can use http://www.fontsquirrel.com/fontface/generator to create a most-compatible CSS containing the various @font-face declarations. 您可以使用http://www.fontsquirrel.com/fontface/generator创建包含各种@font-face声明的最兼容的CSS。

Obviously there will be some old browsers not supporting it - for those you should specify a regular font when using the custom font, eg like this: 显然会有一些旧的浏览器不支持它 - 对于那些你应该在使用自定义字体时指定常规字体,例如:

p { font-family: "your font", sans-serif; }

I'm using FontSquirrel's @font-face kit generator, and it works pretty well in my opinion. 我正在使用FontSquirrel的@ font-face工具包生成器,在我看来它运行得很好。

Check it out at http://www.fontsquirrel.com/fontface/generator 请访问http://www.fontsquirrel.com/fontface/generator查看

Shai 夏嘉曦

FontSquirrel didn't work for me. FontSquirrel并不适合我。 http://transfonter.org/ , on the other hand, was perfect in order to transform DFONT to TTF. 另一方面, http: //transfonter.org/非常适合将DFONT转换为TTF。

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

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