需求:项目中需要在左侧导航栏在每一个功能目录左边显示图标,经过调研,发现使用font awesome技术,利用阿里iconfont图标,生成字体图标用在项目中即可达成目标。
1、首先,打开阿里图标官网,挑选需要的图标加入购物车,然后加入项目下载相应压缩包;
阿里矢量图标库guanwan:http://www.iconfont.cn/plus
选择图标->加购物车->点击右上角购物车->点击添加至项目,若没有则新建(项目名称任意填即可)->下载至本地即可得到需要的自体压缩包文件->解压,找到项目需要的几个文件并拷贝至项目中。
项目必须需要的文件有以下五个,其他可拷贝也可不拷贝:
将这5个文件分别拷贝至项目对应目录,目录示例(自定义的文件夹)如下:
2、然后,修改iconfont.css文件;
主要需要修改引用的四个文件(iconfont.eot,iconfont.woff,iconfont.ttf,iconfont.svg)的相对路径:
@font-face {
font-family: "iconfont";
src: url('../fonts/iconfont.eot?t=1586877904068'); /* IE9 */
src: url('../fonts/iconfont.eot?t=1586877904068#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('data:application/x-font-woff2;charset=utf-8;base64,d09GMgABAAAAABH8AAsAAAAAH/AAABGuAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHEIGVgCFMgqvDKU/ATYCJANECyQABCAFhG0HggIbNRqzItg4AAjJM8j+ywNuyAAd1g2RUL1qgnQNiIX65x38/qz1WgOOY+zgp3fqrEAsgxp7rD8iREgVOsJQSh7+W3u9b3c+YcClhKyiqqtQIqv2eBQy6tsKy66KpmRE/nfabi98nr/bDrWmmpaXa39GaX+adcuxhMVYlEJIsCiGp7n9e3eLvA3kswBk1IioRdMLmUgMaaNG2Bu01YQdE0wwhpWIVVj5Z3UOEIDM915V1eBQ1TgEI/fMCQxWQPJb+S00Ztxp7nqENYJ3n6dQnkXOqT3ptTQ//593+c6WOdW3jO64Co30yV1HcrkD0p3fNe//ruvvStlT9qGQSB4KXNJ56bzffaDGVuCWK8bwsI6HNEVICdSccjTsfQSt0aXHcOsPM3AWm0rU1oAVvziBpjmGsofObu4zFcncCuhzUXKaqSSKJM6BUD9epUybxEsV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H93oKXtEZqeLrhWAXPnWyUQiDyk2rPCR5xT/jcRyJClarxpbhVzYYzzFWO4J6gNBNx5HgUq39Y30nM7qEzqqe3PQ041EoKYmhtpN8tlXLEVnjV3HBk1WWlKEna9xMIDZwZQUmF/7KqPxatRxL1syeOeWKk4s9CqTAQA=') format('woff2'),
url('../fonts/iconfont.woff?t=1586877904068') format('woff'),
url('../fonts/iconfont.ttf?t=1586877904068') format('truetype'), /* chrome, firefox, opera, Safari, Android, iOS 4.2+ */
url('../fonts/iconfont.svg?t=1586877904068#iconfont') format('svg'); /* iOS 4.1- */
}
3、在需要用到字体图标的jsp等文件引用iconfont.css;
<link href="${ctxStatic}/bootstrap/customfont/css/iconfont.css" type="text/css" rel="stylesheet" />
4、最后就可以通过以下类名引用图标,如下是一部分字体图标的content图标编码。
.icon-icons03:before {
content: "\e69c";
}
.icon-shengouheimingdan:before {
content: "\e63b";
}
.icon-shujugengxin:before {
content: "\e616";
}
.icon-jiansuo:before {
content: "\e612";
}
注意引用时,需要先添加iconfont类名,再添加 icon图标名字,才能生效。
总结:下载阿里自带的图标来实现iconfont,有一个好处,是可以在自己所建立的项目中继续追加图标,如果一段时间后发现图标不够用,想要新加一些图标,可以用这种方式,只要将新增的图标放进购物车加入原来的图标项目文件夹下(即你的购物车中项目目录)再次下载压缩包,然后将新的压缩包文件替换web项目对应文件夹下的文件即可。
参考网站:https://blog.csdn.net/weixin_36185028/article/details/53416185
https://blog.csdn.net/qq_41061352/article/details/79414167