Home  >  Article  >  Web Front-end  >  How to make icon from symbol in svg

How to make icon from symbol in svg

不言
不言Original
2018-08-08 11:15:082462browse

The content of this article is about how to create icons from symbols in svg. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

1. cnpm i gulp -g

2. Create a new gulpfile.js file

var gulp = require('gulp');
var svgSymbols = require('gulp-svg-symbols');
gulp.task('sprites',function(){
    return gulp.src('assets/svg/*.svg').pipe(svgSymbols()).pipe(gulp.dest('assets'));
})

3. Create a new assets/svg and put the downloaded svg into the svg file

Tip: Change the svg file name to the required id

4. Run gulp sprites

5. Use it directly in HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
    .icon{
        width:32px;
        height:32px;
        fill:red;
    }
    </style>
</head>
<body>
    <svg class="icon">
        <use xlink:href="/assets/svg-symbols.svg#boat"></use>
    </svg>
</body>
</html>

Related articles Recommended:

SVG drawing function: svg to draw a flower (with code)

The use of 53207a333cb59025d48bd080b9112b21 elements and marker attributes in svg Introduction

The above is the detailed content of How to make icon from symbol in svg. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn