How to change color of SVG image using CSS (jQuery SVG image replacement)?

后端 未结 17 2176
死守一世寂寞
死守一世寂寞 2020-11-21 17:36

This is a self Q&A of a handy piece of code I came up with.

Currently, there isn\'t an easy way to embed an SVG image and then have access to the SVG elements vi

17条回答
  •  别那么骄傲
    2020-11-21 18:10

    Since SVG is basically code, you need just contents. I used PHP to obtain content, but you can use whatever you want.

    
    

    Then, I've printed content "as is" inside a div container

    To finnaly set rule to container's SVG childs on CSS

    .fill-class > svg { 
        fill: orange;
    }
    

    I got this results with a material icon SVG:

    1. Mozilla Firefox 59.0.2 (64-bit) Linux

    1. Google Chrome66.0.3359.181 (Build oficial) (64 bits) Linux

    1. Opera 53.0.2907.37 Linux

提交回复
热议问题