a.進入阿里巴巴矢量圖標庫www.iconfont.cn挑選所需的圖標,加入購物車css
b.點擊網頁中的購物車下載代碼html
Unicode 是字體在網頁端最原始的應用方式,特色是:web
使用步驟以下:注意:新版 iconfont 支持多色圖標,這些多色圖標在 Unicode 模式下將不能使用,若是有需求建議使用symbol 的引用方式bootstrap
@font-face { font-family: 'iconfont'; src: url('iconfont.eot'); src: url('iconfont.eot?#iefix') format('embedded-opentype'), url('iconfont.woff2') format('woff2'), url('iconfont.woff') format('woff'), url('iconfont.ttf') format('truetype'), url('iconfont.svg#iconfont') format('svg'); }
第二步:定義使用 iconfont 的樣式瀏覽器
.iconfont { font-family: "iconfont" !important; font-size: 16px; font-style: normal; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
第三步:挑選相應圖標並獲取字體編碼,應用於頁面svg
<span class="iconfont"></span>
完整代碼:性能
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> @font-face { font-family: 'iconfont'; src: url('iconfont.eot'); src: url('iconfont.eot?#iefix') format('embedded-opentype'), url('iconfont.woff2') format('woff2'), url('iconfont.woff') format('woff'), url('iconfont.ttf') format('truetype'), url('iconfont.svg#iconfont') format('svg'); } .iconfont { font-family: "iconfont" !important; font-size: 16px; font-style: normal; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } </style> </head> <body> <span class="iconfont"></span> </body> </html>
注意:CSS代碼塊中的 @font-face 內的 src: url('iconfont.eot'); 中的 url 即爲以前準備階段下載的源碼文件夾下的對應文件,此處的完整代碼的文件路徑與 iconfont.eot 在同一目錄下,若相應文件不在同一目錄下請修改url參數。
實現效果:字體
font-class 是 Unicode 使用方式的一種變種,主要是解決 Unicode 書寫不直觀,語意不明確的問題。編碼
與 Unicode 使用方式相比,具備以下特色:url
第一步:引入項目下面生成的 fontclass 代碼(即爲準備階段下載的代碼文件中的iconfont.css文件)重要!!!:
<link rel="stylesheet" href="./iconfont.css">
第二步:挑選相應圖標並獲取類名,應用於頁面:
<span class="iconfont icon-setup"></span>
這是一種全新的使用方式,應該說這纔是將來的主流,也是平臺目前推薦的用法。相關介紹能夠參考這篇文章 這種用法實際上是作了一個 SVG 的集合,與另外兩種相比具備以下特色:
font-size
, color
來調整樣式。使用步驟以下:
<script src="./iconfont.js"></script>
<style> .icon { width: 1em; height: 1em; vertical-align: -0.15em; fill: currentColor; overflow: hidden; } </style>
第三步:挑選相應圖標並獲取類名,應用於頁面:
<svg class="icon" aria-hidden="true">
<use xlink:href="#icon-setup"></use>
</svg>
index.html
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <title></title> <link rel="stylesheet" href="css/bootstrap.css" /> <link rel="stylesheet" href="css/iconfont-style.css" /> </head> <body> <a class="btn btn-lg btn-primary"><i class="icon icon-info"></i> More About</a> </body> </html>
iconfont-style.css
@font-face { font-family: 'iconfont'; src:url('../fonts/iconfont.eot?-8vg322'); src:url('../fonts/iconfont.eot?#iefix-8vg322') format('embedded-opentype'), url('../fonts/iconfont.woff?-8vg322') format('woff'), url('../fonts/iconfont.ttf?-8vg322') format('truetype'), url('../fonts/iconfont.svg?-8vg322#iconfont') format('svg'); font-weight: normal; font-style: normal; } [class^="icon-"], [class*=" icon-"] { font-family: 'iconfont'; speak: none; font-style: normal; font-weight: normal; font-variant: normal; text-transform: none; line-height: 1; /* Better Font Rendering =========== */ -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } .icon-user-female:before { content: "\e106"; } .icon-user-follow:before { content: "\e064"; } .icon-user-following:before { content: "\e065"; } 更多定義的icon此處省略........
引用的 fonts 目錄下的文件:
效果圖:
更多精彩的效果圖展現: