One of the simple techniques you can do and put the image in preto e branco
and then put a película de cor
above it, using rgba color, or hexadecimal with transparency as you see fit. This makes it easier for you to change the color values later with jQuery or JS.
See an example of the same image in multiple colors with CSS only. I encapsulated the image in one div
and put a filter grayscale(100%)
then using a pseudo element ::after
in div
I put a colored film over the image and used a mix-blend-mode
to make a "mix" between the color and the image.
See that in the example below I made a blend with "scree
" and another with "overlay
", you can use any other blend-mode and still adjust the Alpha channel in color rgba
to have a better result for each image type.
OBS: I left some comments on CSS to help you
* {
padding: 0;
margin: 0;
box-sizing: border-box;
line-height: 0;
}
div {
display: inline-block;
position: relative;
}
div[class] img {
filter: grayscale(100%); /* filtro que deixa a imagem preto e branco */
}
div[class]::after {
content: "";
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
}
div.red::after {
background-color: rgba(255, 0, 0, .5); /* .5 é onde vc contra a opacidade da cor rgbA*/
mix-blend-mode: screen; /* aqui vc pode testar outrs filtros para ver o que da o melhor resultado para sua imagem*/
}
div.blue::after {
background-color: rgba(0, 0, 255, .5);
mix-blend-mode: overlay;
}
<div><img src="http://placecage.com/130/250" alt=""></div>
<div class="peb" ><img src="http://placecage.com/130/250" alt="cor"></div>
<div class="red" ><img src="http://placecage.com/130/250" alt="cor"></div>
<div class="blue"><img src="http://placecage.com/130/250" alt="cor"></div>
Documentation about CSS filters: https://developer.mozilla.org/en-US/docs/Web/CSS/filter
Documentation about Mix-Blend-Mode: https://developer.mozilla.org/en-US/docs/Web/CSS/mix-blend-mode
CSS
does not change colors of specific parts of image... you could adopt change the image itself. Having several images for your various color schemes simply change thesrc
of the image.– Lauro Moraes
I tried that too, I did that:
var bordaMenina = document.getElementById("dtb61iMap");
 bordaMenina.src = "img/corpo_meninaY.png";
but it didn’t work.– Dr.G
You want to change the color or the src of the image?
– Sam
It is better to work by changing the image src same.
– Sveen
you want the image to be monochromatic (type always the same image only with different colors) or you want to change the image file like red.jpg to yellow.jpg etc.
– hugocsl