5

I want to use css, to fill a certain color on my image, it will have a blur reduction. enter image description here

I tried many ways but colors can not be inserted on the image. Please tell me the parameters so that I can adjust the width or height, or the opacity, change the color.

Tran Audi
  • 587
  • 1
  • 6
  • 22

3 Answers3

15

You can use pseudoelement afterto position the color above the image as this:

div, img {width:100%;}
div {position:relative;}
div:after {
  width:100%;
  content:'';
  display:block;
  position:absolute;
  top:0;
  left:0;
  background: linear-gradient(to right, rgba(247,247,49,1) 0%,rgba(255,255,255,0) 69%);
  height:100%;
}
<div>
  <img src="http://img.andrewprokos.com/TORONTO-PANORAMIC-SKYLINE-DUSK-1200PX.jpg" alt="">
</div>
Alvaro Menéndez
  • 8,766
  • 3
  • 37
  • 57
4

You can apply multiple background images on a div.

Gradient overlay can be created with linear-gradient().

.image-box {
  height: 100px;
  background-image: linear-gradient(to right, gold 30%, transparent 80%),
                    url('https://i.imgur.com/waDgcnc.jpg');
  background-repeat: no-repeat;
  background-size: 100% 100%, cover;
}
<div class="image-box"></div>
Mohammad Usman
  • 37,952
  • 20
  • 92
  • 95
2

Try below

div.parent{width:100%;}
img{width:50%}
div.parent {position:relative;}
div.parent:after {
  width:100%;
  content:'';
  display:block;
  position:absolute;
  top:0;
  left:0;
  background: linear-gradient(to right, rgba(247,247,49,1) 33%,rgba(255,255,255,0) 94%);
  height:100%;
}
span img{visibility:hidden;}
label:before {
  width:100%;
  content:'';
  display:block;
  position:absolute;
  top:0;
  left:0;
  background: linear-gradient(to right, rgba(247,247,49,1) 52%,rgba(255,255,255,0) 94%);
  height:100%;
}
<div class="parent">
  <span><img src="https://i.ytimg.com/vi/QsRE4wQf39Y/maxresdefault.jpg" alt=""></span><label><img class="banner" src="https://i.ytimg.com/vi/QsRE4wQf39Y/maxresdefault.jpg" alt=""></label>
</div>
Dhaarani
  • 1,350
  • 1
  • 13
  • 23