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

后端 未结 17 1975
死守一世寂寞
死守一世寂寞 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

    I wrote a directive to solve this issue with AngularJS. It is available here - ngReusableSvg.

    It replaces the SVG element after it's been rendered, and places it inside a div element, making its CSS easily changeable. This helps using the same SVG file in different places using different sizes/colors.

    The usage is simple:

    
    
    

    After that, you can easily have:

    .svg-class svg {
        fill: red; // whichever color you want
    }
    

提交回复
热议问题