给你个参考吧,不用伪类也可以,在html中加个div什么的样式和:after一样就行了
Document.imgbox{
width:200px;
height: 140px;
position:relative;
overflow: hidden;
}
img{
width:100%;
}
.imgbox:after{
position:absolute;
left: 0;
top:0;
display: block;
width:100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
content: attr(data-text);
transition:all 1s ease;
transform: translateY(-100%);
color: #FFF;
}
.imgbox:hover:after{
transform: translateY(0);
}