img src SVG changing the styles with CSS

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

html

\"Logo\"

css

.logo-img path {
           


        
22条回答
  •  不要未来只要你来
    2020-11-22 02:04

    This might be helpful for people using PHP in combination with .svg images that they want to manipulate with CSS.

    You can't overwrite properties inside a img tag with CSS. But when the svg source code is embedded in the HTML you surely can. I like to resolve this issue with a require_once function where I include a .svg.php file. It's like importing an image but you can still overwrite styles with CSS!

    First include the svg file:

    
    

    And it includes this icon for example:

    
    

    Now we can easily change the fill color like this with CSS:

    svg path {
      fill: blue;
    }
    

    I first tried to solve this problem with file_get_contents() but the solution above is much faster.

提交回复
热议问题