答案 0 :(得分:5)
您可以使用伪元素after
将颜色定位在图像上方,如下所示:
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>
&#13;
答案 1 :(得分:2)
您可以在div
上应用多个背景图片。
可以使用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;
}
&#13;
<div class="image-box"></div>
&#13;
答案 2 :(得分:1)
尝试以下
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>