您可以在悬停时使用单个颜色渐变使用第二个附加背景。
.image1 {
display: inline-block;
height: 300px;
width: 300px;
background: url("http://www.avocat.dac-proiect.ro/wp/wp-content/themes/twentyfourteen/images/images1440/b1.jpg");
margin-left: auto;
vertical-align: top;
}
.image1:hover {
background: linear-gradient(to bottom, rgba(0, 0, 128, 0.25), rgba(0, 0, 128, 0.25)), url("http://www.avocat.dac-proiect.ro/wp/wp-content/themes/twentyfourteen/images/images1440/b1.jpg");
}
<div class="image1">
</div>
作为替代,定位伪元素如果在div将有内容。
.image1 {
display: inline-block;
height: 300px;
width: 300px;
background: url("http://www.avocat.dac-proiect.ro/wp/wp-content/themes/twentyfourteen/images/images1440/b1.jpg");
margin-left: auto;
vertical-align: top;
color: white;
position: relative;
z-index: 1;
}
.image1:hover:after {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 128, 0.5);
z-index: -1;
}
<div class="image1">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Unde magni officia odit enim magnam eaque modi illo dolorum necessitatibus cumque dolore recusandae nisi eos. Libero!</p>
</div>
链接没有按”尝试覆盖的改变alpha通道t工作,并没有提供图像。 – 2015-03-19 12:37:27
https://jsfiddle.net/3q81h1es/3/如果您不必支持旧浏览器 – 2015-03-19 12:45:15