使用单个元素,为特征图像使用伪元素(:before),并使用适当的悬停样式设置其不透明度并显示与基础第二幅图像的混合。我加入了一个渐进的图像转换,只是为了让它看起来更好一点。
html:
<div class="my-image-holder">
text and other contents we don\'t want affected by opacity
</div>
css:
.my-image-holder {
position: relative;
z-index:1;
width:200px;
height:200px;
margin:30px;
background-image: url(\'//some-url-to-second-image\');
background-size: contain;
font-size: 1.2em;
color: white;
}
.my-image-holder:before {
z-index:-1;
position:absolute;
width:200px;
height:200px;
left:0;
top:0;
content: url(\'//some-url-to-featured-image\');
opacity:1.0;
-webkit-transition: opacity 1s linear;
-o-transition: opacity 1s linear;
-moz-transition: opacity 1s linear;
transition: opacity 1s linear;
}
.my-image-holder:hover:before {
opacity:0.5;
}
Example JSFiddle