当前位置:   article > 正文

如何在前端项目中单独引入 ElementUI 图标以及使用_element-icons.woff

element-icons.woff

前言

首先 element-ui 图标是基于字体文件的的形式实现的,如woff和ttf等。有时候一些需求用CSS的before和after为元素实现,自然用到 content 属性,而这个content不仅仅可以承载空格,还可以承载字符编码的。

一、准备好 ElementUI 的图标文件

(1)在项目中使用 npm i element-ui --force 导入依赖,然后找到字体图标文件(element-icons.woff 和 element-icons.ttf),如下图所示。

 (2)还要找到icon.css文件

二、在项目的全局样式文件中引入字体图标和图标样式

(1)字体存放在项目的 /public/element-ui/fonts 目录中,然后在 global.less 或 global.scss 等全局样式文件中引入该字体,随便起一个名称,如:element-ui-icons

(2)复制 icon.css 的样式代码到全局样式文件中

  1. *, *::before, *::after {
  2. margin: 0;
  3. padding: 0;
  4. box-sizing: inherit;
  5. }
  6. html, body {
  7. width: 100%;
  8. height: 100%;
  9. }
  10. #app {
  11. width: 100%;
  12. height: 100%;
  13. }
  14. /* ---- ---- ---- ---- ^ ElementUI ICON ---- ---- ---- ---- */
  15. @font-face {
  16. font-family: 'element-ui-icons';
  17. src: url('/element-ui/fonts/element-icons.woff') format('woff'),
  18. url('/element-ui/fonts/element-icons.ttf') format('truetype');
  19. font-weight: normal;
  20. font-display: "auto";
  21. font-style: normal;
  22. }
  23. [class*=" el-icon-"],[class^=el-icon-] {
  24. font-family: element-ui-icons;
  25. font-style: normal;
  26. font-weight: 400;
  27. font-variant: normal;
  28. text-transform: none;
  29. line-height: 1;
  30. vertical-align: baseline;
  31. display: inline-block;
  32. -webkit-font-smoothing: antialiased;
  33. -moz-osx-font-smoothing: grayscale;
  34. }
  35. .el-icon-ice-cream-round:before{content:"\e6a0"}
  36. .el-icon-ice-cream-square:before{content:"\e6a3"}
  37. .el-icon-lollipop:before{content:"\e6a4"}
  38. .el-icon-potato-strips:before{content:"\e6a5"}
  39. .el-icon-milk-tea:before{content:"\e6a6"}
  40. .el-icon-ice-drink:before{content:"\e6a7"}
  41. .el-icon-ice-tea:before{content:"\e6a9"}
  42. .el-icon-coffee:before{content:"\e6aa"}
  43. .el-icon-orange:before{content:"\e6ab"}
  44. .el-icon-pear:before{content:"\e6ac"}
  45. .el-icon-apple:before{content:"\e6ad"}
  46. .el-icon-cherry:before{content:"\e6ae"}
  47. .el-icon-watermelon:before{content:"\e6af"}
  48. .el-icon-grape:before{content:"\e6b0"}
  49. .el-icon-refrigerator:before{content:"\e6b1"}
  50. .el-icon-goblet-square-full:before{content:"\e6b2"}
  51. .el-icon-goblet-square:before{content:"\e6b3"}
  52. .el-icon-goblet-full:before{content:"\e6b4"}
  53. .el-icon-goblet:before{content:"\e6b5"}
  54. .el-icon-cold-drink:before{content:"\e6b6"}
  55. .el-icon-coffee-cup:before{content:"\e6b8"}
  56. .el-icon-water-cup:before{content:"\e6b9"}
  57. .el-icon-hot-water:before{content:"\e6ba"}
  58. .el-icon-ice-cream:before{content:"\e6bb"}
  59. .el-icon-dessert:before{content:"\e6bc"}
  60. .el-icon-sugar:before{content:"\e6bd"}
  61. .el-icon-tableware:before{content:"\e6be"}
  62. .el-icon-burger:before{content:"\e6bf"}
  63. .el-icon-knife-fork:before{content:"\e6c1"}
  64. .el-icon-fork-spoon:before{content:"\e6c2"}
  65. .el-icon-chicken:before{content:"\e6c3"}
  66. .el-icon-food:before{content:"\e6c4"}
  67. .el-icon-dish-1:before{content:"\e6c5"}
  68. .el-icon-dish:before{content:"\e6c6"}
  69. .el-icon-moon-night:before{content:"\e6ee"}
  70. .el-icon-moon:before{content:"\e6f0"}
  71. .el-icon-cloudy-and-sunny:before{content:"\e6f1"}
  72. .el-icon-partly-cloudy:before{content:"\e6f2"}
  73. .el-icon-cloudy:before{content:"\e6f3"}
  74. .el-icon-sunny:before{content:"\e6f6"}
  75. .el-icon-sunset:before{content:"\e6f7"}
  76. .el-icon-sunrise-1:before{content:"\e6f8"}
  77. .el-icon-sunrise:before{content:"\e6f9"}
  78. .el-icon-heavy-rain:before{content:"\e6fa"}
  79. .el-icon-lightning:before{content:"\e6fb"}
  80. .el-icon-light-rain:before{content:"\e6fc"}
  81. .el-icon-wind-power:before{content:"\e6fd"}
  82. .el-icon-baseball:before{content:"\e712"}
  83. .el-icon-soccer:before{content:"\e713"}
  84. .el-icon-football:before{content:"\e715"}
  85. .el-icon-basketball:before{content:"\e716"}
  86. .el-icon-ship:before{content:"\e73f"}
  87. .el-icon-truck:before{content:"\e740"}
  88. .el-icon-bicycle:before{content:"\e741"}
  89. .el-icon-mobile-phone:before{content:"\e6d3"}
  90. .el-icon-service:before{content:"\e6d4"}
  91. .el-icon-key:before{content:"\e6e2"}
  92. .el-icon-unlock:before{content:"\e6e4"}
  93. .el-icon-lock:before{content:"\e6e5"}
  94. .el-icon-watch:before{content:"\e6fe"}
  95. .el-icon-watch-1:before{content:"\e6ff"}
  96. .el-icon-timer:before{content:"\e702"}
  97. .el-icon-alarm-clock:before{content:"\e703"}
  98. .el-icon-map-location:before{content:"\e704"}
  99. .el-icon-delete-location:before{content:"\e705"}
  100. .el-icon-add-location:before{content:"\e706"}
  101. .el-icon-location-information:before{content:"\e707"}
  102. .el-icon-location-outline:before{content:"\e708"}
  103. .el-icon-location:before{content:"\e79e"}
  104. .el-icon-place:before{content:"\e709"}
  105. .el-icon-discover:before{content:"\e70a"}
  106. .el-icon-first-aid-kit:before{content:"\e70b"}
  107. .el-icon-trophy-1:before{content:"\e70c"}
  108. .el-icon-trophy:before{content:"\e70d"}
  109. .el-icon-medal:before{content:"\e70e"}
  110. .el-icon-medal-1:before{content:"\e70f"}
  111. .el-icon-stopwatch:before{content:"\e710"}
  112. .el-icon-mic:before{content:"\e711"}
  113. .el-icon-copy-document:before{content:"\e718"}
  114. .el-icon-full-screen:before{content:"\e719"}
  115. .el-icon-switch-button:before{content:"\e71b"}
  116. .el-icon-aim:before{content:"\e71c"}
  117. .el-icon-crop:before{content:"\e71d"}
  118. .el-icon-odometer:before{content:"\e71e"}
  119. .el-icon-time:before{content:"\e71f"}
  120. .el-icon-bangzhu:before{content:"\e724"}
  121. .el-icon-close-notification:before{content:"\e726"}
  122. .el-icon-microphone:before{content:"\e727"}
  123. .el-icon-turn-off-microphone:before{content:"\e728"}
  124. .el-icon-position:before{content:"\e729"}
  125. .el-icon-postcard:before{content:"\e72a"}
  126. .el-icon-message:before{content:"\e72b"}
  127. .el-icon-chat-line-square:before{content:"\e72d"}
  128. .el-icon-chat-dot-square:before{content:"\e72e"}
  129. .el-icon-chat-dot-round:before{content:"\e72f"}
  130. .el-icon-chat-square:before{content:"\e730"}
  131. .el-icon-chat-line-round:before{content:"\e731"}
  132. .el-icon-chat-round:before{content:"\e732"}
  133. .el-icon-set-up:before{content:"\e733"}
  134. .el-icon-turn-off:before{content:"\e734"}
  135. .el-icon-open:before{content:"\e735"}
  136. .el-icon-connection:before{content:"\e736"}
  137. .el-icon-link:before{content:"\e737"}
  138. .el-icon-cpu:before{content:"\e738"}
  139. .el-icon-thumb:before{content:"\e739"}
  140. .el-icon-female:before{content:"\e73a"}
  141. .el-icon-male:before{content:"\e73b"}
  142. .el-icon-guide:before{content:"\e73c"}
  143. .el-icon-news:before{content:"\e73e"}
  144. .el-icon-price-tag:before{content:"\e744"}
  145. .el-icon-discount:before{content:"\e745"}
  146. .el-icon-wallet:before{content:"\e747"}
  147. .el-icon-coin:before{content:"\e748"}
  148. .el-icon-money:before{content:"\e749"}
  149. .el-icon-bank-card:before{content:"\e74a"}
  150. .el-icon-box:before{content:"\e74b"}
  151. .el-icon-present:before{content:"\e74c"}
  152. .el-icon-sell:before{content:"\e6d5"}
  153. .el-icon-sold-out:before{content:"\e6d6"}
  154. .el-icon-shopping-bag-2:before{content:"\e74d"}
  155. .el-icon-shopping-bag-1:before{content:"\e74e"}
  156. .el-icon-shopping-cart-2:before{content:"\e74f"}
  157. .el-icon-shopping-cart-1:before{content:"\e750"}
  158. .el-icon-shopping-cart-full:before{content:"\e751"}
  159. .el-icon-smoking:before{content:"\e752"}
  160. .el-icon-no-smoking:before{content:"\e753"}
  161. .el-icon-house:before{content:"\e754"}
  162. .el-icon-table-lamp:before{content:"\e755"}
  163. .el-icon-school:before{content:"\e756"}
  164. .el-icon-office-building:before{content:"\e757"}
  165. .el-icon-toilet-paper:before{content:"\e758"}
  166. .el-icon-notebook-2:before{content:"\e759"}
  167. .el-icon-notebook-1:before{content:"\e75a"}
  168. .el-icon-files:before{content:"\e75b"}
  169. .el-icon-collection:before{content:"\e75c"}
  170. .el-icon-receiving:before{content:"\e75d"}
  171. .el-icon-suitcase-1:before{content:"\e760"}
  172. .el-icon-suitcase:before{content:"\e761"}
  173. .el-icon-film:before{content:"\e763"}
  174. .el-icon-collection-tag:before{content:"\e765"}
  175. .el-icon-data-analysis:before{content:"\e766"}
  176. .el-icon-pie-chart:before{content:"\e767"}
  177. .el-icon-data-board:before{content:"\e768"}
  178. .el-icon-data-line:before{content:"\e76d"}
  179. .el-icon-reading:before{content:"\e769"}
  180. .el-icon-magic-stick:before{content:"\e76a"}
  181. .el-icon-coordinate:before{content:"\e76b"}
  182. .el-icon-mouse:before{content:"\e76c"}
  183. .el-icon-brush:before{content:"\e76e"}
  184. .el-icon-headset:before{content:"\e76f"}
  185. .el-icon-umbrella:before{content:"\e770"}
  186. .el-icon-scissors:before{content:"\e771"}
  187. .el-icon-mobile:before{content:"\e773"}
  188. .el-icon-attract:before{content:"\e774"}
  189. .el-icon-monitor:before{content:"\e775"}
  190. .el-icon-search:before{content:"\e778"}
  191. .el-icon-takeaway-box:before{content:"\e77a"}
  192. .el-icon-paperclip:before{content:"\e77d"}
  193. .el-icon-printer:before{content:"\e77e"}
  194. .el-icon-document-add:before{content:"\e782"}
  195. .el-icon-document:before{content:"\e785"}
  196. .el-icon-document-checked:before{content:"\e786"}
  197. .el-icon-document-copy:before{content:"\e787"}
  198. .el-icon-document-delete:before{content:"\e788"}
  199. .el-icon-document-remove:before{content:"\e789"}
  200. .el-icon-tickets:before{content:"\e78b"}
  201. .el-icon-folder-checked:before{content:"\e77f"}
  202. .el-icon-folder-delete:before{content:"\e780"}
  203. .el-icon-folder-remove:before{content:"\e781"}
  204. .el-icon-folder-add:before{content:"\e783"}
  205. .el-icon-folder-opened:before{content:"\e784"}
  206. .el-icon-folder:before{content:"\e78a"}
  207. .el-icon-edit-outline:before{content:"\e764"}
  208. .el-icon-edit:before{content:"\e78c"}
  209. .el-icon-date:before{content:"\e78e"}
  210. .el-icon-c-scale-to-original:before{content:"\e7c6"}
  211. .el-icon-view:before{content:"\e6ce"}
  212. .el-icon-loading:before{content:"\e6cf"}
  213. .el-icon-rank:before{content:"\e6d1"}
  214. .el-icon-sort-down:before{content:"\e7c4"}
  215. .el-icon-sort-up:before{content:"\e7c5"}
  216. .el-icon-sort:before{content:"\e6d2"}
  217. .el-icon-finished:before{content:"\e6cd"}
  218. .el-icon-refresh-left:before{content:"\e6c7"}
  219. .el-icon-refresh-right:before{content:"\e6c8"}
  220. .el-icon-refresh:before{content:"\e6d0"}
  221. .el-icon-video-play:before{content:"\e7c0"}
  222. .el-icon-video-pause:before{content:"\e7c1"}
  223. .el-icon-d-arrow-right:before{content:"\e6dc"}
  224. .el-icon-d-arrow-left:before{content:"\e6dd"}
  225. .el-icon-arrow-up:before{content:"\e6e1"}
  226. .el-icon-arrow-down:before{content:"\e6df"}
  227. .el-icon-arrow-right:before{content:"\e6e0"}
  228. .el-icon-arrow-left:before{content:"\e6de"}
  229. .el-icon-top-right:before{content:"\e6e7"}
  230. .el-icon-top-left:before{content:"\e6e8"}
  231. .el-icon-top:before{content:"\e6e6"}
  232. .el-icon-bottom:before{content:"\e6eb"}
  233. .el-icon-right:before{content:"\e6e9"}
  234. .el-icon-back:before{content:"\e6ea"}
  235. .el-icon-bottom-right:before{content:"\e6ec"}
  236. .el-icon-bottom-left:before{content:"\e6ed"}
  237. .el-icon-caret-top:before{content:"\e78f"}
  238. .el-icon-caret-bottom:before{content:"\e790"}
  239. .el-icon-caret-right:before{content:"\e791"}
  240. .el-icon-caret-left:before{content:"\e792"}
  241. .el-icon-d-caret:before{content:"\e79a"}
  242. .el-icon-share:before{content:"\e793"}
  243. .el-icon-menu:before{content:"\e798"}
  244. .el-icon-s-grid:before{content:"\e7a6"}
  245. .el-icon-s-check:before{content:"\e7a7"}
  246. .el-icon-s-data:before{content:"\e7a8"}
  247. .el-icon-s-opportunity:before{content:"\e7aa"}
  248. .el-icon-s-custom:before{content:"\e7ab"}
  249. .el-icon-s-claim:before{content:"\e7ad"}
  250. .el-icon-s-finance:before{content:"\e7ae"}
  251. .el-icon-s-comment:before{content:"\e7af"}
  252. .el-icon-s-flag:before{content:"\e7b0"}
  253. .el-icon-s-marketing:before{content:"\e7b1"}
  254. .el-icon-s-shop:before{content:"\e7b4"}
  255. .el-icon-s-open:before{content:"\e7b5"}
  256. .el-icon-s-management:before{content:"\e7b6"}
  257. .el-icon-s-ticket:before{content:"\e7b7"}
  258. .el-icon-s-release:before{content:"\e7b8"}
  259. .el-icon-s-home:before{content:"\e7b9"}
  260. .el-icon-s-promotion:before{content:"\e7ba"}
  261. .el-icon-s-operation:before{content:"\e7bb"}
  262. .el-icon-s-unfold:before{content:"\e7bc"}
  263. .el-icon-s-fold:before{content:"\e7a9"}
  264. .el-icon-s-platform:before{content:"\e7bd"}
  265. .el-icon-s-order:before{content:"\e7be"}
  266. .el-icon-s-cooperation:before{content:"\e7bf"}
  267. .el-icon-bell:before{content:"\e725"}
  268. .el-icon-message-solid:before{content:"\e799"}
  269. .el-icon-video-camera:before{content:"\e772"}
  270. .el-icon-video-camera-solid:before{content:"\e796"}
  271. .el-icon-camera:before{content:"\e779"}
  272. .el-icon-camera-solid:before{content:"\e79b"}
  273. .el-icon-download:before{content:"\e77c"}
  274. .el-icon-upload2:before{content:"\e77b"}
  275. .el-icon-upload:before{content:"\e7c3"}
  276. .el-icon-picture-outline-round:before{content:"\e75f"}
  277. .el-icon-picture-outline:before{content:"\e75e"}
  278. .el-icon-picture:before{content:"\e79f"}
  279. .el-icon-close:before{content:"\e6db"}
  280. .el-icon-check:before{content:"\e6da"}
  281. .el-icon-plus:before{content:"\e6d9"}
  282. .el-icon-minus:before{content:"\e6d8"}
  283. .el-icon-help:before{content:"\e73d"}
  284. .el-icon-s-help:before{content:"\e7b3"}
  285. .el-icon-circle-close:before{content:"\e78d"}
  286. .el-icon-circle-check:before{content:"\e720"}
  287. .el-icon-circle-plus-outline:before{content:"\e723"}
  288. .el-icon-remove-outline:before{content:"\e722"}
  289. .el-icon-zoom-out:before{content:"\e776"}
  290. .el-icon-zoom-in:before{content:"\e777"}
  291. .el-icon-error:before{content:"\e79d"}
  292. .el-icon-success:before{content:"\e79c"}
  293. .el-icon-circle-plus:before{content:"\e7a0"}
  294. .el-icon-remove:before{content:"\e7a2"}
  295. .el-icon-info:before{content:"\e7a1"}
  296. .el-icon-question:before{content:"\e7a4"}
  297. .el-icon-warning-outline:before{content:"\e6c9"}
  298. .el-icon-warning:before{content:"\e7a3"}
  299. .el-icon-goods:before{content:"\e7c2"}
  300. .el-icon-s-goods:before{content:"\e7b2"}
  301. .el-icon-star-off:before{content:"\e717"}
  302. .el-icon-star-on:before{content:"\e797"}
  303. .el-icon-more-outline:before{content:"\e6cc"}
  304. .el-icon-more:before{content:"\e794"}
  305. .el-icon-phone-outline:before{content:"\e6cb"}
  306. .el-icon-phone:before{content:"\e795"}
  307. .el-icon-user:before{content:"\e6e3"}
  308. .el-icon-user-solid:before{content:"\e7a5"}
  309. .el-icon-setting:before{content:"\e6ca"}
  310. .el-icon-s-tools:before{content:"\e7ac"}
  311. .el-icon-delete:before{content:"\e6d7"}
  312. .el-icon-delete-solid:before{content:"\e7c9"}
  313. .el-icon-eleme:before{content:"\e7c7"}
  314. .el-icon-platform-eleme:before{content:"\e7ca"}
  315. .el-icon-loading{
  316. -webkit-animation: rotating 2s linear infinite;
  317. animation: rotating 2s linear infinite
  318. }
  319. @-webkit-keyframes rotating {
  320. 0% {
  321. -webkit-transform: rotateZ(0);
  322. transform: rotateZ(0)
  323. }
  324. 100% {
  325. -webkit-transform: rotateZ(360deg);
  326. transform: rotateZ(360deg)
  327. }
  328. }
  329. @keyframes rotating{
  330. 0% {
  331. -webkit-transform: rotateZ(0);
  332. transform: rotateZ(0)
  333. }
  334. 100% {
  335. -webkit-transform: rotateZ(360deg);
  336. transform: rotateZ(360deg)
  337. }
  338. }
  339. /* ---- ---- ---- ---- / ElementUI ICON ---- ---- ---- ---- */

三、使用方式

(1)Html代码

  1. <template>
  2. <div style="padding: 50px;">
  3. <i class="el-icon el-icon-star-on"></i>
  4. <span>HelloWorld ~</span>
  5. </div>
  6. </template>
  7. <script>
  8. export default {
  9. data: () => ({
  10. // ...
  11. }),
  12. methods: {
  13. // ...
  14. }
  15. }
  16. </script>
  17. <style>
  18. i {
  19. display: block !important;
  20. width: 100px !important;
  21. height: auto;
  22. font-size: 25px !important;
  23. color: #5e7ce0 !important;
  24. box-shadow: 0 0 5px #5e7ce0;
  25. }
  26. span {
  27. display: block;
  28. width: 100px;
  29. height: 30px;
  30. background-color: #5e7ce0;
  31. text-align: center;
  32. line-height: 30px;
  33. color: #fff;
  34. }
  35. span::before {
  36. font-family: element-ui-icons;
  37. content: '\e7b9';
  38. font-size: 16px;
  39. }
  40. </style>

四、运行效果

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号