Change color of PNG image via CSS?

后端 未结 16 1618
自闭症患者
自闭症患者 2020-11-22 07:33

Given a transparent PNG displaying a simple shape in white, is it possible to somehow change the color of this through CSS? Some kind of overlay or what not?

16条回答
  •  余生分开走
    2020-11-22 08:06

    There's no need for a whole font set if you only need one icon, plus I feel it being more "clean" as an individual element. So, for this purpose, in HTML5 you can place a SVG directly inside the document flow. Then you can define a class in your .CSS stylesheet and access its background color with the fill property:

    Working fiddle: http://jsfiddle.net/qmsj0ez1/

    Note that, in the example, I've used :hoverto illustrate the behaviour; if you just want to change color for the "normal" state, you should remove the pseudoclass.

提交回复
热议问题