前言
UI 设计给的切图是 .png
格式。但想与 Element UI icon 用法类似,方案如下。
实现
步骤一
准备图片
步骤二
新建文件,可使用 CSS 预处理语言 styl
或 scss
。
stylus 方式
文件 icon.styl
/* 定义一个混合 */
cfgIcon(w, h) {
display: inline-block;
width: w;
height: h;
background-size: w h;
margin-right: 8px;
}
.my-icon-loading {
background: url(./images/loading.png);
cfgIcon(10px,10px);
}