One of the simple techniques that you can do and put the image in% with% and then put preto e branco
over it, using color rgba, or Hexadecimal with transparency as you see fit. This makes it easy for you to change the color values later with jQuery or JS.
See an example of the same multi-color image with CSS only. I encapsulated the image in a película de cor
and put a div
filter after using a grayscale(100%)
pseudo element in ::after
I placed a colored film over the image and used div
to make a "mix" between the color and the image.
See that in the example below I made a blend with " mix-blend-mode
" and another with " scree
", you can use any other blend mode and still adjust the Alpha channel in color overlay
to have a better result for each type of image.
OBS: I left comments in 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>
CSS filters documentation: link
Mix-Blend-Mode documentation: link