简体   繁体   English

如何使用字体图标作为背景图像?

[英]How can I use a font icon as a background image?

1) I know I can use a font icon using , pseudo selectors (before, after) and "content", but it is not a scalable solution, because I need to make many changes to padding, left, top etc in different situations 1)我知道我可以使用,伪选择器(之前,之后)和“内容”使用字体图标,但这不是可扩展的解决方案,因为我需要在不同情况下对填充,左,上等进行很多更改

2) Using Data URI an svg is ok, but I need to change the fill/color of the svg based on different actions. 2)使用数据URI可以使svg正常运行,但是我需要根据不同的操作来更改svg的填充/颜色。 I tried the fill property but it is not really working. 我尝试了fill属性,但它实际上没有用。

I can change/edit the color external but I have a lot of variations and again doesn't scale 我可以更改/编辑外部颜色,但是我有很多变化,并且再次无法缩放


The icon fonts(ex: FontAwesome) come with SVG files for the browsers. 图标字体(例如FontAwesome)随浏览器的SVG文件一起提供。 It is possible to use somehow that file in css (like image sprites) ? 可以以某种方式在CSS中使用该文件(例如图像精灵)吗?

If you want to modify properties of SVG's it will have to be placed inline. 如果要修改SVG的属性,则必须内联放置。 So using an SVG as a background and modifying properties won't work. 因此,使用SVG作为背景修改属性将不起作用。

Libraries like FontAwesome give you a font , not svg 's which you can't set as a background either. 像FontAwesome这样的库为您提供font ,而不是svg ,您也不能将其设置为背景。

I don't see the problem of using the psuedo-selectors :before and :after for this. 我看不到使用psuedo-selectors :before和:after的问题。 They are very scalable in my opinion. 我认为它们具有很好的可扩展性。

If you really want to do it differently you should share some of your code with us so we can get a better understanding of what you're trying to do. 如果您真的想以其他方式进行操作,则应与我们共享一些代码,以便我们更好地了解您要执行的操作。

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

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