我有一个带有background-image
的
rgba(0,0,0,0.1)
)覆盖 background-image。
我想知道是否有一种只有一个
我尝试了多种方法:
<div class="the-div" id="test-1"></div>
<div class="the-div" id="test-2"></div>
<div class="the-div" id="test-3"></div>
并且这个CSS:
.the-div {
background-image: url('the-image');
margin: 10px;
width: 200px;
height: 80px;
}
#test-1:hover {
background-color: rgba(0,0,0,0.1);
}
#test-2:hover {
background: url('the-image'), rgba(0,0,0,0.1);
}
#test-3:hover {
background: rgba(0,0,0,0.1);
}
请查看这个样例。
我所看到的唯一选择是制作另一张带有遮罩层的图片,使用JavaScript预加载它,然后使用.the-div:hover { background: url('the-new-image'); }
。但是,我想要一个仅基于CSS的解决方案(更加整洁; 请求较少; 减少硬盘开销)。是否有任何方法?
-moz
和-ms
版本现在应该不再需要,同样适用于旧版WebKit的符号。我猜-o
也不再需要了,因为新版Opera基于WebKit。所以你只需要两行代码。 - Wladimir Palant