简体   繁体   English

用 svg 替换字体真棒图标

[英]Replace font awesome icon with an svg

I want to replace a font-awesome icon with and svg.我想用 svg 替换一个字体很棒的图标。

For example, if the css class is class="'fa fa-square'" , how can it be changed in order to use an svg file with the same shape, square.svg ?例如,如果 css 类是class="'fa fa-square'" ,如何更改它以使用具有相同形状square.svg的 svg 文件?

All the font-awesome svg's are located in this handy github repo Font Awesome SVG's所有 font-awesome svg 都位于这个方便的 github repo Font Awesome SVG's

You can insert the svg into a span, like so: *note you need to change the inline height and width, but leave the viewbox as is.您可以将 svg 插入到跨度中,如下所示:*注意您需要更改行内高度和宽度,但保持视图框不变。 To change the color of an svg, use fill: #colorvalue要更改 svg 的颜色,请使用填充:#colorvalue

<span>
    <svg width="1792" height="1792" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1664 416v960q0 119-84.5 203.5t-203.5 84.5h-960q-119 0-203.5-84.5t-84.5-203.5v-960q0-119 84.5-203.5t203.5-84.5h960q119 0 203.5 84.5t84.5 203.5z"/></svg>
</span>

I had the same desire, and found my way with Icomoon.io :我有同样的愿望,并通过Icomoon.io找到了自己的方式:

You can (for free) generate a font including only the icons you selected, with a nice GUI:您可以(免费)生成仅包含您选择的图标的字体,并带有漂亮的 GUI:

In picture: Icomoon - GUI图片中:Icomoon - GUI

(sorry I can't embed picture here, I'm new to SO and don't have enough 'reputation'..) (对不起,我不能在这里嵌入图片,我是新来的,没有足够的“声誉”..)

The CSS and HTML are also provided:还提供了 CSS 和 HTML:

In picture: Icomoon - GUI 2图片中:Icomoon - GUI 2

Only drawback, the free tier does not include WOFF2 file (but you get .eot, svg, ttf and woff - you may find a woff2 generator online)唯一的缺点是,免费套餐不包括 WOFF2 文件(但您可以获得 .eot、svg、ttf 和 woff - 您可以在网上找到 woff2 生成器)

You prefer SVG?你更喜欢SVG? No problem, it's also provided!没问题,它还提供!

In picture: Icomoon - generate SVG图片中:Icomoon - 生成 SVG

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM