iconMoon:字體圖標(iconfont)解決方案及使用教程


1、iconMoon 是什么?

字體圖標(icon font)解決方案,iconMoon 可以把svg圖片生成字體圖標,開發者可以通過設置字體大小和字體顏色來改變圖標的大小和顏色而不失真

 

2、官網地址:https://icomoon.io

 

 

 

3、點擊右上角的【iconMoon App】 進入圖標上傳、選擇和生成頁面

 

 

4、圖標上傳、選擇和生成頁面

  4.1 把准備好的svg文件,通過【import Icons】入口或直接將svg文件拖至該頁面,上傳成功后,如下圖所示:

   

 

  4.2 選中要生成字體文件的圖標

  點擊圖標,選中要生成的圖標;選中后圖標會呈現高亮狀態;如下圖所示:

    

 

  4.3 點擊右下角【Generate Font】生成字體圖標文件和demo

        

 

  4.4 生成預覽

   

 

    此時,可以選中className 進行修改

    

 

  修改后

    

 

5、 點擊右下角的【download】進行生成、下載

 

 

 

解壓並打開下載好的文件,看到如下目錄結構:

 

 

注:

fonts文件:需要放到項目靜態資源目錄

selection.json文件: 

下次需要修改圖標的時候,需要用到;把selection.json文件導入至iconMoon即可獲取當前已有的圖標;

類似歷史記錄,對字體圖標的維護非常重要,需妥善保存;每次修改都要更新該文件

 

 

在截圖頁面(https://icomoon.io/app/#/select),將selection.json文件拖進來即可看到已有圖標集合

 

style.css文件:字體圖標對應的css文件

 

@font-face {
  font-family: 'icomoon';
  src:  url('fonts/icomoon.eot?9f7p7u');
  src:  url('fonts/icomoon.eot?9f7p7u#iefix') format('embedded-opentype'),
    url('fonts/icomoon.ttf?9f7p7u') format('truetype'),
    url('fonts/icomoon.woff?9f7p7u') format('woff'),
    url('fonts/icomoon.svg?9f7p7u#icomoon') format('svg');
  font-weight: normal;
  font-style: normal;
}

[class^="icon-"], [class*=" icon-"] {
  /* use !important to prevent issues with browser extensions that change fonts */
  font-family: 'icomoon' !important;
  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-comment:before {
  content: "\e904";
}
.icon-like .path1:before {
  content: "\e918";
  color: rgb(61, 133, 247);
}
.icon-like .path2:before {
  content: "\e91b";
  margin-left: -1em;
  color: rgb(255, 255, 255);
}
.icon-tip .path1:before {
  content: "\e919";
  color: rgb(61, 133, 247);
}
.icon-tip .path2:before {
  content: "\e91c";
  margin-left: -1em;
  color: rgb(61, 133, 247);
}
.icon-tip .path3:before {
  content: "\e91d";
  margin-left: -1em;
  color: rgb(255, 255, 255);
}
.icon-tip .path4:before {
  content: "\e91e";
  margin-left: -1em;
  color: rgb(255, 255, 255);
}
.icon-tip .path5:before {
  content: "\e91f";
  margin-left: -1em;
  color: rgb(255, 255, 255);
}
.icon-tip .path6:before {
  content: "\e920";
  margin-left: -1em;
  color: rgb(255, 255, 255);
}
.icon-tip .path7:before {
  content: "\e921";
  margin-left: -1em;
  color: rgb(255, 255, 255);
}
.icon-news .path1:before {
  content: "\e91a";
  color: rgb(61, 133, 247);
}
.icon-news .path2:before {
  content: "\e922";
  margin-left: -1em;
  color: rgb(61, 133, 247);
}
.icon-news .path3:before {
  content: "\e923";
  margin-left: -1em;
  color: rgb(61, 133, 247);
}
.icon-news .path4:before {
  content: "\e924";
  margin-left: -1em;
  color: rgb(61, 133, 247);
}
.icon-news .path5:before {
  content: "\e925";
  margin-left: -1em;
  color: rgb(61, 133, 247);
}
.icon-news .path6:before {
  content: "\e926";
  margin-left: -1em;
  color: rgb(61, 133, 247);
}
.icon-news .path7:before {
  content: "\e927";
  margin-left: -1em;
  color: rgb(61, 133, 247);
}
.icon-news .path8:before {
  content: "\e928";
  margin-left: -1em;
  color: rgb(61, 133, 247);
}
.icon-news .path9:before {
  content: "\e929";
  margin-left: -1em;
  color: rgb(61, 133, 247);
}
.icon-news .path10:before {
  content: "\e92a";
  margin-left: -1em;
  color: rgb(61, 133, 247);
}
.icon-news .path11:before {
  content: "\e92b";
  margin-left: -1em;
  color: rgb(61, 133, 247);
}
.icon-news .path12:before {
  content: "\e92c";
  margin-left: -1em;
  color: rgb(255, 255, 255);
}

 

  

需要注意的是,截圖中所示的.path*對應的class

 

 

這是因為:圖標被iconMoon解析為“多色(彩色)”。由於字體字形只能有一種顏色,因此IcoMoon必須使用多個路徑(path)來顯示多色(彩色)圖標。

這也是IcoMoon優於iconfont(阿里字體圖標方案)的地方;iconfont不支持多色圖標的展示。

 

這些path在html中引用的時候也有要求:path路徑之間不允許換行和空格!

引用方式如下:

 

<i class="icomoon icon-tip"><span class="path1"></span><span class="path2"></span><span class="path3"></span><span class="path4"></span><span class="path5"></span><span class="path6"></span><span class="path7"></span></icon>

 

  

以上。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM