0

This is the code that I have been using to make an image grayscale.

img {
    -webkit-filter: grayscale(100%) !important;
    filter: grayscale(100%) !important;
}

1 Answer 1

1

unclear what you are asking, but filter can take more than one value.

mix-blend-mode can be used to mix image with other elements (backgrounds, text, ...)

some examples untill you clear up your question

img {
  -webkit-filter: grayscale(100%);
          filter: grayscale(100%);
  box-shadow: 0 0 0 3px white;
}

img:nth-child(2) {
  -webkit-filter: grayscale(100%) contrast(160%);
          filter: grayscale(100%) contrast(160%);
}

img:nth-child(3) {
  -webkit-filter: grayscale(50%) contrast(400%) blur(2px);
          filter: grayscale(50%) contrast(400%) blur(2px);
}

img:nth-child(4) {
  -webkit-filter: grayscale(0%) contrast(200%) blur(0px) sepia(100%);
          filter: grayscale(0%) contrast(200%) blur(0px) sepia(100%);
}

img:nth-child(5) {
  -webkit-filter: grayscale(0%) contrast(200%) blur(0px) sepia(0%) brightness(200%);
          filter: grayscale(0%) contrast(200%) blur(0px) sepia(0%) brightness(200%);
}

img:nth-child(6) {
  -webkit-filter: grayscale(0%) contrast(100%) blur(0px) sepia(0%) brightness(100%) hue-rotate(150deg);
          filter: grayscale(0%) contrast(100%) blur(0px) sepia(0%) brightness(100%) hue-rotate(150deg);
}

img:nth-child(7) {
  -webkit-filter: grayscale(0%) contrast(100%) blur(0px) sepia(0%) brightness(100%) hue-rotate(0deg) invert(1);
          filter: grayscale(0%) contrast(100%) blur(0px) sepia(0%) brightness(100%) hue-rotate(0deg) invert(1);
}

img:nth-child(8) {
  -webkit-filter: grayscale(0%) contrast(100%) blur(0px) sepia(0%) brightness(100%) hue-rotate(0deg) invert(0) saturate(5);
          filter: grayscale(0%) contrast(100%) blur(0px) sepia(0%) brightness(100%) hue-rotate(0deg) invert(0) saturate(5);
}

img:nth-child(9) {
  -webkit-filter: grayscale(0%) contrast(100%) blur(0px) sepia(0%) brightness(100%) hue-rotate(0deg) invert(0) saturate(5) opacity(0.5);
          filter: grayscale(0%) contrast(100%) blur(0px) sepia(0%) brightness(100%) hue-rotate(0deg) invert(0) saturate(5) opacity(0.5);
}

img:nth-child(11) {
  filter: grayscale(0%) contrast(100%) blur(0px) sepia(0%) brightness(100%) hue-rotate(0deg) invert(0) saturate(1) opacity(1);
  mix-blend-mode: multiply;
}
p {
  position:absolute;
  color:white;
  font-size:3em; 
}

body {
  background: -webkit-linear-gradient(45deg, tomato, turquoise, lime, gray, white, gold);
  background: linear-gradient(45deg, tomato, turquoise, lime, gray, white, gold);
  background-size: 205px 206px;
}
<img src="http://lorempixel.com/200/200/nature/2" /> 
<img src="http://lorempixel.com/200/200/nature/2" /> 
<img src="http://lorempixel.com/200/200/nature/2" /> 
<img src="http://lorempixel.com/200/200/nature/2" /> 
<img src="http://lorempixel.com/200/200/nature/2" /> 
<img src="http://lorempixel.com/200/200/nature/2" /> 
<img src="http://lorempixel.com/200/200/nature/2" /> 
<img src="http://lorempixel.com/200/200/nature/2" /> 
<img src="http://lorempixel.com/200/200/nature/2" /><p>some text</p> 
<img src="http://lorempixel.com/200/200/nature/2" />

span {
  display: inline-block;
  animation: hue-rotate 5s infinite;
}
img {
  display: block;
  mix-blend-mode: multiply;
}
span:hover {
  animation:none;
}
.a {
  background:none;
}
.b {
  background: blue;
}
.c {
  background: green;
}
.d {
  background: brown;
}
.e {
  background: yellow;
}
.f {
  background: gray;
}
.g {
  background: purple;
}
.h {
  background: red;
}
@keyframes hue-rotate {
  to {
    filter: hue-rotate(360deg);
  }
}
<span class="a"><img src="http://lorempixel.com/200/200/nature/2" /></span>
<span class="b"><img src="http://lorempixel.com/200/200/nature/2" /></span>
<span class="c"><img src="http://lorempixel.com/200/200/nature/2" /></span>
<span class="d"><img src="http://lorempixel.com/200/200/nature/2" /></span>
<span class="e"><img src="http://lorempixel.com/200/200/nature/2" /></span>
<span class="f"><img src="http://lorempixel.com/200/200/nature/2" /></span>
<span class="g"><img src="http://lorempixel.com/200/200/nature/2" /></span>
<span class="h"><img src="http://lorempixel.com/200/200/nature/2" /></span>

3
  • Like grayscale filter changes the color to black and white, I want my custom color there.@gcyrillus Commented Mar 1, 2016 at 16:09
  • @dipenbaks did you notice the mix-blend-mode effect ?
    – G-Cyrillus
    Commented Mar 1, 2016 at 19:20
  • @dipenbaks updated answer with a mix-blend-mode and hue-rotate first image has no mix-blend-mode. others, on other remains only the mix-blend-mode effect. some other ideas codepen.io/gc-nomade/pen/wouBe once you dig in a few method, you can find the one that suits you and made up your own tuning. make it simple :)
    – G-Cyrillus
    Commented Mar 1, 2016 at 19:44

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