<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>鼠标悬停效果</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="image">
<img src="images/1.jpg" alt="">
</div>
<div class="image">
<img src="images/2.jpg" alt="">
</div>
<div class="image">
<img src="images/3.jpg" alt="">
</div>
</body>
</html>
body{
margin: 0;
padding: 0;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background-color: #333;
}
.image{
width: 260px;
overflow: hidden;
cursor: pointer;
position: relative;
margin: 0 20px;
}
.image img{
width: 100%
}
.image::before{
content: '';
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-size: cover;
filter: grayscale(100%);
transition: .5s linear;
}
.image:hover::before{
width: 0;
}
.image:nth-child(1)::before{
background-image: url(images/1.jpg);
}
.image:nth-child(2)::before{
background-image: url(images/2.jpg);
}
.image:nth-child(3)::before{
background-image: url(images/3.jpg);
}
网友评论