Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add svg to web page? [duplicate]

Tags:

html

css

svg

How can I add an svg to my webpage and change it's color via css?

I've tried:

<img src="my.svg" class="svg"/>

.svg{
    fill: white;
}

But no luck.

CSS only solutions please, and I do not need any fallbacks, only supporting new browsers.

like image 645
panthro Avatar asked Nov 10 '22 09:11

panthro


1 Answers

It won't work this way. You can change the fill color if you're directly including the svg, i.e.:

HTML:

<p>Some other webpage content</p>
<svg class="my-svg">
    <g>
        <path fill="..."></path>
        <path fill="..."></path>
    </g>
</svg>
<p>Some other webpage content</p>

CSS:

.my-svg *{
    fill:white;
}

So, you web-inspect my.svg, and copy-paste its contents to the destination page. Then you can style it.

like image 106
nicael Avatar answered Nov 15 '22 05:11

nicael