Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invert svg image using css?

I'm trying to invert an image file with .svg extension using css. I know .png and .jpg files can be inverted using css webkit properties. I am new on svg images. Is it possible to invert .svg images using css?

I tried using

-webkit-filter:invert(1);         filter:invert(1); 

but it did not work.

like image 391
ADH - THE TECHIE GUY Avatar asked Sep 29 '16 03:09

ADH - THE TECHIE GUY


People also ask

How do you invert an image in CSS?

CSS | invert() Function The invert() function is an inbuilt function that is used to apply a filter to the image to set the invert of the color of the sample image.

How do you invert colors in CSS?

CSS allows you to invert the color of an HTML element by using the invert() CSS function that you can pass to the filter property. Because the default color of the text is black, the color is inverted into white with filter: invert(100%) syntax.


1 Answers

Just style the SVG element directly

svg {   -webkit-filter: invert(100%); /* safari 6.0 - 9.0 */           filter: invert(100%); } 

From IE9 and above you can use SVG in <img src="" /> element.

img { /* svg on an img tag */    -webkit-filter: invert(.75); /* safari 6.0 - 9.0 */            filter: invert(.75);  }
<img src="https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-logo.svg" />

You can set the amount as percentage or as number as this docs says

The amount of the conversion, specified as a <number> or a <percentage>. A value of 100% is completely inverted, while a value of 0% leaves the input unchanged. Values between 0% and 100% are linear multipliers on the effect. The lacuna value for interpolation is 0.

like image 132
Engkus Kusnadi Avatar answered Sep 21 '22 18:09

Engkus Kusnadi