優勢
- 檔案極小
- 載入效能佳
- 支援 CSS 樣式控制(色彩、大小、陰影、旋轉)
- IE6/7 相容
缺點
- 樣式限於扁平化,無法呈現複雜材質
- 行動裝置仍存相容性問題
- 極少數裝置字元編碼衝突
- Firefox/IE9 跨域載入字體檔受限
使用流程
- 製作字體檔:手工工具或線上生成器(如 IcoMoon、Fontello)
@font-face 引入多格式字體(EOT/WOFF/TTF/SVG)
- 定義通用
.icon-* 基礎樣式(font-family、font-smoothing)
- 用
:before 注入字元編碼
程式碼範例
@font-face {
font-family: 'iconfont';
src: url('iconfont.eot'); /* IE9 */
src: url('iconfont.eot?#iefix') format('embedded-opentype'), /* IE6-8 */
url('iconfont.woff') format('woff'),
url('iconfont.ttf') format('truetype'),
url('iconfont.svg#uxiconfont') format('svg'); /* iOS 4.1- */
}
[class^="icon-"], [class*=" icon-"] {
display: inline-block;
speak: none;
font-family: "iconfont";
font-size: 16px;
line-height: 1;
font-style: normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.icon-bell:before { content: "\003432"; }
.icon-search:before { content: "\003433"; }