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

前言

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

实现

步骤一

准备图片

在这里插入图片描述

步骤二

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

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);
}
.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

/* 定义一个混合 */
@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 框架中直接导入即可。

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

使用

el-button

<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>

<i class="cfg-icon-start"/>
<i class="cfg-icon-file"/>
<i class="cfg-icon-file"/>

在这里插入图片描述

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-22 14:10:06       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-22 14:10:06       101 阅读
  3. 在Django里面运行非项目文件

    2024-04-22 14:10:06       82 阅读
  4. Python语言-面向对象

    2024-04-22 14:10:06       91 阅读

热门阅读

  1. 冒烟测试(Smoke Testing)简介

    2024-04-22 14:10:06       33 阅读
  2. 题解:P9426 [蓝桥杯 2023 国 B] 抓娃娃

    2024-04-22 14:10:06       65 阅读
  3. 读《零基础学PYthon》有感

    2024-04-22 14:10:06       150 阅读
  4. GitLab存储空间满了

    2024-04-22 14:10:06       32 阅读
  5. CV 面试指南—深度学习知识点总结(5)

    2024-04-22 14:10:06       35 阅读
  6. Gitlab相关,【推送项目】

    2024-04-22 14:10:06       38 阅读
  7. 11-3.Vue2.x基本列表—列表排序—sort

    2024-04-22 14:10:06       40 阅读