<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS3鼠标经过动画显示图片特效</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: #f5f5f5;
margin: 0;
font-family: Arial, sans-serif;
flex-wrap: wrap;
gap: 30px;
padding: 20px;
}
.gallery {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 20px;
max-width: 1000px;
}
.image-container {
position: relative;
width: 200px;
height: 200px;
border-radius: 10px;
overflow: hidden;
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
transition: all 0.5s ease;
}
.image-container::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: linear-gradient(45deg, #ff9a9e, #fad0c4);
z-index: 1;
transition: all 0.5s ease;
}
.image-container:hover::before {
opacity: 0;
transform: scale(0.5);
}
.image-container img {
width: 100%;
height: 100%;
object-fit: cover;
transform: scale(1.2);
transition: all 0.5s ease;
filter: grayscale(80%);
}
.image-container:hover img {
transform: scale(1);
filter: grayscale(0%);
}
.image-title {
position: absolute;
bottom: -50px;
left: 0;
width: 100%;
padding: 10px;
background: rgba(0,0,0,0.7);
color: white;
text-align: center;
transition: all 0.5s ease;
z-index: 2;
}
.image-container:hover .image-title {
bottom: 0;
}
/* 插入的链接样式 */
.custom-link {
position: fixed;
bottom: 20px;
right: 20px;
color: #333;
text-decoration: none;
font-size: 14px;
background: rgba(255,255,255,0.8);
padding: 8px 15px;
border-radius: 20px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
transition: all 0.3s ease;
}
.custom-link:hover {
background: #fff;
transform: translateY(-3px);
box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}
</style>
</head>
<body>
<div class="gallery">
<div class="image-container">
<img src="https://picsum.photos/id/10/800/800" alt="自然风景">
<div class="image-title">自然风景</div>
</div>
<div class="image-container">
<img src="https://picsum.photos/id/11/800/800" alt="城市建筑">
<div class="image-title">城市建筑</div>
</div>
<div class="image-container">
<img src="https://picsum.photos/id/12/800/800" alt="海滩风光">
<div class="image-title">海滩风光</div>
</div>
<div class="image-container">
<img src="https://picsum.photos/id/13/800/800" alt="山脉景色">
<div class="image-title">山脉景色</div>
</div>
<div class="image-container">
<img src="https://picsum.photos/id/14/800/800" alt="森林景观">
<div class="image-title">森林景观</div>
</div>
<div class="image-container">
<img src="https://picsum.photos/id/15/800/800" alt="湖泊风光">
<div class="image-title">湖泊风光</div>
</div>
</div>
</body>
</html>
CSS3鼠标经过动画显示图片特效
于 2025-06-16 14:54:02 首次发布