Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to colorize an image in CSS?

Tags:

css

image

colors

Is there a cross-browser way to use CSS to change the shade of an image. For example, if I have a grayscale icon (an img element), I'd like it to change the colors to sepia on hover.

It would have to work on browsers other than IE, so I can't use filter. Is there some CSS 3 trick that would allow that?

like image 959
Goran Jovic Avatar asked Dec 11 '11 12:12

Goran Jovic


People also ask

How do I color an image in CSS?

We can change the image color in CSS by combining the opacity() and drop-shadow() functions in the filter property. We can provide the color of the shadow from the drop-shadow function, and we can set the shadow as thin as possible so that the image's color will only change without forming an actual shadow.

How do I change the color of a png in CSS?

Use filter function to change the png image color. Filter property is mainly used to set the visual effect to the image. There are many property value exist to the filter function.

How do I color a white image in CSS?

If the product team was kind enough to also provide a white version of the image, you can simply toggle the image's src on hover. This can be done using JavaScript. You can use an onmouseover function that sets the image's src to white. png and then an onmouseleave function that sets the image's src to black.

How do you change the color of an image to blue in CSS?

To change the color of an image to blue, we have to combine the below three functions with the filter property: sepia(%) – Adds sepia color to the image. hue-rotate(%) – Rotates the image hue on the color circle. saturate(%) – Adjusts the saturation level.


1 Answers

if you want to modify an image in css, it isn't possible to do that. but you can play with the opacity property. yeah that only set the image opacity, but it will be a nice effect. here is an example :

img{-webkit-transition:opacity .3s ease-in-out;}
img:hover{opacity:.6}

that snippet will give a nice transition effect of fade-in and out image into transparent.

in other case, you can use image sprite to do what you want :)

like image 62
Ariona Rian Avatar answered Sep 25 '22 23:09

Ariona Rian