@Font-face的基本用法及讓全部瀏覽器都兼容的方法
2024-08-30 08:35:22
供稿:網(wǎng)友
@Font-face基本介紹:
@font-face 是一個(gè)css2的一個(gè)語(yǔ)法,它允許你在網(wǎng)頁(yè)上顯示一個(gè)自定義的字體。即使客戶機(jī)器上可以沒(méi)有安裝這種字體,網(wǎng)頁(yè)也可以顯示。
本文將介紹@font-face的基本用法,以及在所有瀏覽器都能使用的方法。
@Font-face基本語(yǔ)法:
@font-face { font-family: <a-remote-font-name>; src: <source> [,<source>]*; [font-weight: <weight>]; [font-style: <style>]; }
具體介紹請(qǐng)移步到這里:https://developer.mozilla.org/en/css/@font-face
一個(gè)例子:
@font-face { font-family: MyHelvetica; src: local("Helvetica Neue Bold"), local("HelveticaNeue-Bold"), url(MgOpenModernaBold.ttf); font-weight: bold; }
font-family是字體的名稱,src是字體的路徑,可以是客戶本機(jī)字體,也可以是服務(wù)器上的字體。
@Font-face目前瀏覽器的兼容性:
•Webkit/Safari(3.2+):TrueType/OpenType TT (.ttf) 、OpenType PS (.otf);
•Opera (10+): TrueType/OpenType TT (.ttf) 、 OpenType PS (.otf) 、 SVG (.svg);
•Internet Explorer: 自ie4開(kāi)始,支持EOT格式的字體文件;ie9支持WOFF;
•Firefox(3.5+): TrueType/OpenType TT (.ttf)、 OpenType PS (.otf)、 WOFF (since Firefox 3.6)
•Google Chrome:TrueType/OpenType TT (.ttf)、OpenType PS (.otf)、WOFF since version 6
由上面可以得出:.eot + .ttf /.otf + svg + woff = 所有瀏覽器的完美支持。
@Font-face 讓所有瀏覽器都兼容的方法:
有一個(gè)專門(mén)用于@font-face 的字體網(wǎng)站:http://www.fontsquirrel.com/fontface/generator
fontsquirrel 網(wǎng)站提供了一個(gè)免費(fèi)的 @font-face Kit Generator工具,可以生成不同的字體格式,并且直接用css和html給出demo。使你可以直接引用到你的網(wǎng)站上。你可以直接使用 fontsquirrel 網(wǎng)站提供 的一些字體,也可以上傳你自己的字體還是用。
@font-face Kit Generator demo
http://www.xunzou.com/demo/font-face/Chopin-Script-fontfacekit/demo.html
@font-face Kit Generator demo
http://www.font2web.com/
@font-face demo
http://www.xunzou.com/demo/font-face/font-face.html
其它font服務(wù):
Google font API,也是一個(gè)不錯(cuò)的字體服務(wù),另外一些字體替換還有cufon等。
Google font API 可以參考之前的一片文章:http://www.xunzou.com/blog/post/619.html