微信小程序如何引入外部字体库iconfont的图标

it2022-05-23  72

每天学习一点点 编程PDF电子书、视频教程免费下载:http://www.shitanlife.com/code

 

微信小程序不能识别很多文件, 其中就包括外部的字体文件. 那我们怎么突破他的防火线呢, 这里主要用得就是在线的字体库. 它的使用不像之前引用阿里巴巴字体库那样简单。

步骤如下:

1.在 阿里巴巴字体库 选购喜欢的字体并下载压缩文件, 详细方法这里不赘述, 不懂的请看 阿里巴巴字体库使用方法

2.Copy iconfont.css文件的内容, 可以选择放在全局的 app.wxss 或者 任何你要用到字体的 .wxss文件

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 @font-face { font-family :  "iconfont" ;    src :  url ( 'iconfont.eot?t=1484311526877' );  /* IE9*/    src :  url ( 'iconfont.eot?t=1484311526877#iefix' )  format ( 'embedded-opentype' ),  /* IE6-IE8 */    url ( 'iconfont.woff?t=1484311526877' )  format ( 'woff' ),  /* chrome, firefox */    url ( 'iconfont.ttf?t=1484311526877' )  format ( 'truetype' ),  /* chrome, firefox, opera, Safari, Android, iOS 4.2+*/    url ( 'iconfont.svg?t=1484311526877#iconfont' )  format ( 'svg' );  /* iOS 4.1- */ }   .iconfont {    font-family : "iconfont"  !important ;    font-size : 16px ;    font-style : normal ;    -webkit-font-smoothing: antialiased;    -moz-osx-font-smoothing: grayscale; }   .icon-sousuo:before {  content :  "\e604" ; }   .icon-stars:before {  content :  "\e605" ; }

  

3.用阿里巴巴字体库创建的项目的 unicode 代码 替换 刚才赋值的最上层代码:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 //更改后的代码 @font-face {    font-family :  'iconfont' ;   /* project id 218229 */    src :  url ( '//at.alicdn.com/t/font_1oyoojup1w34bo6r.eot' );    src :  url ( '//at.alicdn.com/t/font_1oyoojup1w34bo6r.eot?#iefix' )  format ( 'embedded-opentype' ),    url ( '//at.alicdn.com/t/font_1oyoojup1w34bo6r.woff' )  format ( 'woff' ),    url ( '//at.alicdn.com/t/font_1oyoojup1w34bo6r.ttf' )  format ( 'truetype' ),    url ( '//at.alicdn.com/t/font_1oyoojup1w34bo6r.svg#iconfont' )  format ( 'svg' ); }   .iconfont {    font-family : "iconfont"  !important ;    font-size : 16px ;    font-style : normal ;    -webkit-font-smoothing: antialiased;    -moz-osx-font-smoothing: grayscale; }   .icon-sousuo:before {  content :  "\e604" ; }   .icon-stars:before {  content :  "\e605" ; }

  引用如下:

1 2 //iconfont 必须添加的,后面的是选中的样式类名(老套路了) < text  class="iconfont icon-shouye"></ text >

 

转载于:https://www.cnblogs.com/scode2/p/8952614.html

相关资源:数据结构—成绩单生成器

最新回复(0)