《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"/>
相关推荐
DsirNg1 小时前
页面栈溢出问题修复总结
前端·微信小程序
小徐_23331 小时前
uni-app 也能远程调试?使用 PageSpy 打开调试的新大门!
前端·微信小程序·uni-app
大怪v1 小时前
【Virtual World 03】上帝之手
前端·javascript
招来红月3 小时前
记录JS 实用API
javascript
别叫我->学废了->lol在线等3 小时前
演示 hasattr 和 ** 解包操作符
开发语言·前端·python
霍夫曼3 小时前
UTC时间与本地时间转换问题
java·linux·服务器·前端·javascript
DARLING Zero two♡3 小时前
浏览器里跑 AI 语音转写?Whisper Web + cpolar让本地服务跑遍全网
前端·人工智能·whisper
꒰ঌ小武໒꒱4 小时前
文件上传全维度知识体系:从基础原理到高级优化
javascript·node.js
Lovely Ruby4 小时前
前端er Go-Frame 的学习笔记:实现 to-do 功能(三),用 docker 封装成镜像,并且同时启动前后端数据库服务
前端·学习·golang
深红4 小时前
玩转小程序AR-实战篇
前端·微信小程序·webvr