《ElementUI 基础知识》png 图片扩展 icon用法

前言

UI 设计给的切图是 .png 格式。但想与 Element UI icon 用法类似,方案如下。

实现

步骤一

准备图片

步骤二

新建文件,可使用 CSS 预处理语言 stylscss

stylus 方式

文件 icon.styl

css 复制代码
/* 定义一个混合 */
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);
}
.my-icon-stop {
    background: url(./images/stop.png);
    cfgIcon(10px,10px);
}
.my-icon-start {
    background: url(./images/start.png);
    cfgIcon(10px,10px);
}

scss 方式

文件 icon.scss

css 复制代码
/* 定义一个混合 */
@mixin cfgIcon($w, $h) {
    display: inline-block;
    width: $w;
    height: $h;
    background-size: $w $h;
    margin-right: 8px;
}

.cfg-icon-loading {
    background: url(./images/loading.png);
    @include cfgIcon(10px,10px);
}
.cfg-icon-stop {
    background: url(./images/stop.png);
    @include cfgIcon(10px,10px);
}
.cfg-icon-start {
    background: url(./images/start.png);
    @include cfgIcon(10px,10px);
}

步骤三

全局导入。在 Vue 框架中直接导入即可。

vue 复制代码
<template>
  <div id="app">
    <router-view/>
  </div>
</template>
<style lang="stylus">
@import './css/icon.styl'
</style>

使用

el-button

html 复制代码
<el-button icon="my-icon-start" class="el-button--active">启动服务</el-button>
<el-button icon="my-icon-stop">停止服务</el-button>
<el-button icon="my-icon-loading">重启服务</el-button>

直接用 <i>

html 复制代码
<i class="cfg-icon-start"/>
<i class="cfg-icon-file"/>
<i class="cfg-icon-file"/>
相关推荐
YH丶浩1 分钟前
React 实现爱心花园动画
前端·react.js·前端框架
啵啵学习9 分钟前
浏览器插件,提示:此扩展程序未遵循 Chrome 扩展程序的最佳实践,因此已无法再使用
前端·chrome·浏览器·插件·破解
Mintopia15 分钟前
# 使用 Three.js 实现带随机障碍物的小车行驶模拟
前端·javascript·three.js
Mintopia15 分钟前
图形学与坐标系入门教学
前端·javascript·计算机图形学
独立开阀者_FwtCoder31 分钟前
8年磨一剑,Koa 3.0 正式发布!看看带来了哪些新功能
前端·javascript·后端
Frankabcdefgh37 分钟前
初中级前端面试全攻略:自我介绍模板、项目讲解套路与常见问答
前端·面试·职场和发展
2401_8784545339 分钟前
thymeleaf的使用和小结
前端·javascript·学习
brzhang1 小时前
宝藏发现:Sim Studio,一款让AI工作流搭建变简单的开源利器
前端·后端·github
2301_799404911 小时前
AJAX 介绍
前端·ajax·axios
脚本语言_菜鸟1 小时前
音频转base64
android·javascript·音视频