最近接觸了一個將字體拓展的方法,感受很不錯,因此積累一下。javascript
最近接觸的項目一直再用antd,它自己已經提供了不少圖標,可是依然不夠用,因此須要咱們拓展出來一些。java
當咱們下載到本地以後,就會有幾個文件,咱們只須要將這幾個文件引入到項目中,就能夠使用了web
.iconfont-mixin() { &:before { font-family:"anticon","anticon_user" !important; } } //上面的方法能夠將anticon字體拓展出來,變成原來的anticon和anticon_user的並集,這一句很關鍵,能夠覆蓋less的全部字體文件
@font-face {font-family: "anticon_user";
src: url('iconfont.eot?t=1466754517'); /* IE9*/
src: url('iconfont.eot?t=1466754517#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('iconfont.woff?t=1466754517') format('woff'), /* chrome, firefox */
url('iconfont.ttf?t=1466754517') format('truetype'), /* chrome, firefox, opera, Safari, Android, iOS 4.2+*/
url('iconfont.svg?t=1466754517#anticon_user') format('svg'); /* iOS 4.1- */
}chrome
.anticon_user {
font-family:"anticon_user" !important;
font-size:16px;
font-style:normal;
-webkit-font-smoothing: antialiased;
-webkit-text-stroke-width: 0.2px;
-moz-osx-font-smoothing: grayscale;
}
.anticon-setting:before { content: "\e109"; }
.anticon-bus:before { content: "\e10a"; }
.anticon-mobile:before { content: "\e10b"; }
.anticon-file-text:before { content: "\e10d"; }
.anticon-database:before { content: "\e10e"; }
.anticon-cloud-upload-mid:before { content: "\e10f"; }
.anticon-dashboard:before { content: "\e110"; }
.anticon-medicine-o:before { content: "\e100"; }
.anticon-tip-o:before { content: "\e101"; }
.anticon-earth-o:before { content: "\e102"; }
.anticon-box-o:before { content: "\e103"; }
.anticon-calendar-o:before { content: "\e104"; }
.anticon-money-o:before { content: "\e105"; }
.anticon-pencil-o:before { content: "\e106"; }
.anticon-voice-o:before { content: "\e107"; }
.anticon-sign:before { content: "\e108"; }antd
const menuIcon = { "1": "dashboard", "2": "database", "3": "mobile", "4": "bus" } <Icon type={menuIcon[4]}/> 就能夠將這個圖片拓展出來,由於antd自己封裝會將Icon的type="xxx",變成class="anticon-xxx",因此就能夠拓展出來了。