img src SVG changing the styles with CSS

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

html

\"Logo\"

css

.logo-img path {
           


        
22条回答
  •  旧巷少年郎
    2020-11-22 02:02

    You could set your SVG as a mask. That way setting a background-color would act as your fill color.

    HTML

    
    

    CSS

    .logo {
        background-color: red;
        -webkit-mask: url(logo.svg) no-repeat center;
        mask: url(logo.svg) no-repeat center;
    }
    

    JSFiddle: https://jsfiddle.net/KuhlTime/2j8exgcb/
    MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/mask

    Please check whether your browser supports this feature: https://caniuse.com/#search=mask

提交回复
热议问题