Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Filter grayscale: I want it Black

Tags:

css

I am using the following css to convert my color images to grayscale.

img.desaturate{
    filter: grayscale(100%);
    -webkit-filter: grayscale(100%);
    -moz-filter: grayscale(100%);
    -ms-filter: grayscale(100%);
    -o-filter: grayscale(100%);
    filter: url(desaturate.svg#greyscale);
    filter: gray;
    -webkit-filter: grayscale(1);
}

BUT I want it Black (rgb(0,0,0) or #000000), and not grey. Is it possible?

like image 628
DextrousDave Avatar asked Apr 09 '13 14:04

DextrousDave


People also ask

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

Simply paste your color (as a hex code) into the text input, then click "compute filters". This will convert your hex color into a css color, and compare it with the "real color". Then, just copy and paste the CSS code as needed.

How do I make an image black in CSS?

0% will make the image completely black. 100% (1) is default, and represents the original image. Values over 100% will provide results with more contrast. Applies a drop shadow effect to the image.

How do I change the color of a picture filter?

Very easy when using the hue-rotate() filter. Make your images red, which has a hue value of 0, then use a hue chart to grab the colours you require for the hue rotation. Use the filter:grayscale(1) to set all images to grey, then on hover, set the grayscale to 0 and adjust the colour values. My pleasure.


3 Answers

Try using:

filter: brightness(0%);
like image 140
Reinier Koops Avatar answered Oct 19 '22 01:10

Reinier Koops


I supose you want only black & white images, like a vector image or something, that's it? You could try playing with the saturate brightness and contrast filters:

filter: gray saturate(0%) brightness(70%) contrast(1000%);

Demo in jsfiddle (Demo only works in Webkit, I'm too lazy to write all vendor extensions :P)

like image 10
Arkana Avatar answered Oct 19 '22 02:10

Arkana


I'm late to the party, but here's the best solution I found so far:

filter: brightness(0) invert(1);
like image 5
vector-e Avatar answered Oct 19 '22 02:10

vector-e