img src SVG changing the styles with CSS

后端 未结 22 1967
予麋鹿
予麋鹿 2020-11-22 01:16

html

\"Logo\"

css

.logo-img path {
           


        
22条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 01:53

    Edit your SVG file, add fill="currentColor" to svg tag and make sure to remove any other fill property from the file.

    For example:

    ...
    
    

    Note that currentColor is a keyword (not a fixed color in use).

    After that, you can change the color using CSS, by setting the color property of the element or from it's parent.

    Example:

    .div-with-svg-inside {
        color: red;
    }
    

    I forgot to say, you must insert the SVG this way:

          
            
          
    
    

    Note that #img is the id of the svg tag inside svg file.

    Another way of doing it: https://css-tricks.com/cascading-svg-fill-color/

提交回复
热议问题