0

I will be grateful if you can help me to change image's color using only CSS3 (image has shades of Grey).

using some properties of CSS3 like filter ... thank you in advance!

2

3 Answers 3

1

You can achieve this by overlaying a pseudo-element on top of the image and using the mix-blend-mode property (check browser support). For the example below, I've used overlay.

*{box-sizing:border-box;margin:0;padding:0;}
figure{
    display:inline-block;
    position:relative;
}
img{
    vertical-align:middle;
}
figure::after{
    background:#f00;
    bottom:0;
    content:"";
    left:0;
    mix-blend-mode:overlay;
    opacity:.75;
    pointer-events:none;
    position:absolute;
    right:0;
    top:0;
}
<figure>
    <img alt="" height="250" src="https://unsplash.it/500/250?image=1082&gravity=south" width="500">
</figure>

2
  • You're welcome. If this or one of the others answers has addressed your issue to your satisfaction, you might consider accepting it.
    – Shaggy
    Commented Feb 21, 2017 at 10:19
  • Good answer ! To be noted that mix-blend-mode: color; gives an alternative in the same direction, and luminosity in the opposite (the color under the image).
    – vals
    Commented Feb 21, 2017 at 18:15
0
You can user filter css3,
.filter-me {
  filter: <filter-function> [<filter-function>]* | none
}
Where is one of:
    blur()
    brightness()
    contrast()
    drop-shadow()
    grayscale()
    hue-rotate()
    invert()
    opacity()
    saturate()
    sepia()
    url() - for applying SVG filters
    custom() - "coming soon"
1
  • First of all, thank you for your response ! I already tried some of this functions, but I did not get the right result ... Other wise can you tell me the right value of each function in order to convert a black image into red image ? Commented Feb 20, 2017 at 13:56
0

as far as i know you can't turn an original grey image into a colored one. closest thing to that is using sepia but that won't work as you want.

the idea is to use at first a colored image , make it gray with grayscale(100%) or saturate(0%) and then ( maybe on an event eg:hover,click,focus etc ) color it again with one of the filter properties

see example below

img {
filter:grayscale(100%);
height:200px;
width:auto;
}
img:hover {
filter:hue-rotate(100deg);
}
<img src="https://placeimg.com/640/480/animals">

let me know if it helps

1
  • first of all, thank you for your retour! Just to be more clear, my original image is grey and I want to tinted with only one color (red or green or orange) using CSS3 Commented Feb 20, 2017 at 15:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.