dfs*_*fsq 101
你可以用这个简单的CSS/HTML实现这个目的:
.image-container {
position: relative;
width: 200px;
height: 300px;
}
.image-container .after {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: none;
color: #FFF;
}
.image-container:hover .after {
display: block;
background: rgba(0, 0, 0, .6);
}
Run Code Online (Sandbox Code Playgroud)
HTML
<div class="image-container">
<img src="http://lorempixel.com/300/200" />
<div class="after">This is some content</div>
</div>
Run Code Online (Sandbox Code Playgroud)
UPD:这是一个不错的最终演示,带有一些额外的风格.
.image-container {
position: relative;
display: inline-block;
}
.image-container img {display: block;}
.image-container .after {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: none;
color: #FFF;
}
.image-container:hover .after {
display: block;
background: rgba(0, 0, 0, .6);
}
.image-container .after .content {
position: absolute;
bottom: 0;
font-family: Arial;
text-align: center;
width: 100%;
box-sizing: border-box;
padding: 5px;
}
.image-container .after .zoom {
color: #DDD;
font-size: 48px;
position: absolute;
top: 50%;
left: 50%;
margin: -30px 0 0 -19px;
height: 50px;
width: 45px;
cursor: pointer;
}
.image-container .after .zoom:hover {
color: #FFF;
}Run Code Online (Sandbox Code Playgroud)
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet"/>
<div class="image-container">
<img src="http://lorempixel.com/300/180" />
<div class="after">
<span class="content">This is some content. It can be long and span several lines.</span>
<span class="zoom">
<i class="fa fa-search"></i>
</span>
</div>
</div>Run Code Online (Sandbox Code Playgroud)
jbu*_*483 30
您可以为此使用伪元素,并将您的图像放在悬停上:
.image {
position: relative;
height: 300px;
width: 300px;
background: url(http://lorempixel.com/300/300);
}
.image:before {
content: "";
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
transition: all 0.8s;
opacity: 0;
background: url(http://lorempixel.com/300/200);
background-size: 100% 100%;
}
.image:hover:before {
opacity: 0.8;
}Run Code Online (Sandbox Code Playgroud)
<div class="image"></div>Run Code Online (Sandbox Code Playgroud)
And*_*ole 18
把这个答案放在这里,因为它是谷歌的最高结果。
如果你想要一个快速简单的方法:
filter: brightness(0.2);
Run Code Online (Sandbox Code Playgroud)
*不兼容IE
Emi*_*nov 12
这有点晚了,但是当搜索覆盖方法时,这个帖子在Google中作为最高结果出现.
你可以简单地使用一个 background-blend-mode
.foo {
background-image: url(images/image1.png), url(images/image2.png);
background-color: violet;
background-blend-mode: screen multiply;
}
Run Code Online (Sandbox Code Playgroud)
这样做是它采用第二个图像,并使用多重混合模式将其与背景颜色混合,然后使用屏幕混合模式将第一个图像与第二个图像和背景颜色混合.您可以使用16种不同的混合模式来实现任何叠加.
乘法,屏幕,叠加,变暗,变亮,颜色闪避,颜色燃烧,强光,柔光,差异,排斥,色调,饱和度,颜色和亮度.