<!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>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Arial', sans-serif;
background-color: #f5f5f5;
padding: 40px 20px;
color: #333;
}
.container {
max-width: 1200px;
margin: 0 auto;
}
h1 {
text-align: center;
margin-bottom: 40px;
color: #2c3e50;
}
.note {
background-color: #f8f4e5;
padding: 15px;
border-left: 4px solid #e67e22;
margin: 20px 0 40px;
border-radius: 0 4px 4px 0;
}
.note a {
color: #e67e22;
text-decoration: none;
}
.note a:hover {
text-decoration: underline;
}
.gallery {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
gap: 30px;
}
.image-card {
position: relative;
overflow: hidden;
border-radius: 8px;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
height: 300px;
transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.image-card:hover {
transform: translateY(-10px);
box-shadow: 0 15px 30px rgba(0, 0, 0, 0.2);
}
.image-card img {
width: 100%;
height: 100%;
object-fit: cover;
transition: transform 0.5s ease;
}
.image-card:hover img {
transform: scale(1.1);
}
.image-overlay {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background: linear-gradient(to top, rgba(0,0,0,0.8) 0%, rgba(0,0,0,0) 100%);
padding: 20px;
color: white;
transform: translateY(100%);
transition: transform 0.5s ease;
opacity: 0;
}
.image-card:hover .image-overlay {
transform: translateY(0);
opacity: 1;
}
.image-title {
font-size: 24px;
margin-bottom: 10px;
transform: translateY(20px);
transition: transform 0.5s ease 0.1s;
}
.image-card:hover .image-title {
transform: translateY(0);
}
.image-desc {
font-size: 16px;
margin-bottom: 15px;
transform: translateY(20px);
transition: transform 0.5s ease 0.2s;
opacity: 0;
}
.image-card:hover .image-desc {
transform: translateY(0);
opacity: 1;
}
.image-btn {
display: inline-block;
padding: 8px 20px;
background-color: #3498db;
color: white;
text-decoration: none;
border-radius: 4px;
font-size: 14px;
transform: translateY(20px);
transition: all 0.5s ease 0.3s, background-color 0.3s ease;
opacity: 0;
}
.image-card:hover .image-btn {
transform: translateY(0);
opacity: 1;
}
.image-btn:hover {
background-color: #2980b9;
}
/* 特效1 - 从底部滑入 */
.effect-1 .image-overlay {
transform: translateY(100%);
}
/* 特效2 - 从顶部滑入 */
.effect-2 .image-overlay {
top: 0;
bottom: auto;
background: linear-gradient(to bottom, rgba(0,0,0,0.8) 0%, rgba(0,0,0,0) 100%);
transform: translateY(-100%);
}
/* 特效3 - 从右侧滑入 */
.effect-3 .image-overlay {
width: 70%;
height: 100%;
left: auto;
right: 0;
background: linear-gradient(to left, rgba(0,0,0,0.8) 0%, rgba(0,0,0,0) 100%);
transform: translateX(100%);
}
/* 特效4 - 从左侧滑入 */
.effect-4 .image-overlay {
width: 70%;
height: 100%;
right: auto;
left: 0;
background: linear-gradient(to right, rgba(0,0,0,0.8) 0%, rgba(0,0,0,0) 100%);
transform: translateX(-100%);
}
/* 特效5 - 中心放大 */
.effect-5 .image-overlay {
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0,0,0,0.7);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
transform: scale(0);
border-radius: 8px;
}
.effect-5:hover .image-overlay {
transform: scale(1);
}
/* 特效6 - 旋转效果 */
.effect-6 .image-overlay {
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0,0,0,0.7);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
transform: rotateY(180deg);
opacity: 0;
border-radius: 8px;
}
.effect-6:hover .image-overlay {
transform: rotateY(0deg);
opacity: 1;
}
/* 特效7 - 半透明覆盖 */
.effect-7 .image-overlay {
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(46, 204, 113, 0.8);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
opacity: 0;
transition: opacity 0.5s ease;
}
.effect-7:hover .image-overlay {
opacity: 1;
}
/* 特效8 - 对角线滑入 */
.effect-8 .image-overlay {
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(155, 89, 182, 0.8);
clip-path: polygon(0 100%, 100% 100%, 100% 100%, 0% 100%);
transition: clip-path 0.5s ease;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.effect-8:hover .image-overlay {
clip-path: polygon(0 0, 100% 0, 100% 100%, 0% 100%);
}
</style>
</head>
<body>
<div class="container">
<h1>CSS3鼠标滑过图片文字动画特效</h1>
<div class="gallery">
<!-- 特效1 - 从底部滑入 -->
<div class="image-card effect-1">
<img src="https://source.unsplash.com/random/600x400?nature" alt="自然风景">
<div class="image-overlay">
<h3 class="image-title">自然之美</h3>
<p class="image-desc">探索大自然的壮丽景观和无限魅力</p>
<a href="#" class="image-btn">查看详情</a>
</div>
</div>
<!-- 特效2 - 从顶部滑入 -->
<div class="image-card effect-2">
<img src="https://source.unsplash.com/random/600x400?city" alt="城市风光">
<div class="image-overlay">
<h3 class="image-title">城市之光</h3>
<p class="image-desc">感受现代都市的繁华与活力</p>
<a href="#" class="image-btn">查看详情</a>
</div>
</div>
<!-- 特效3 - 从右侧滑入 -->
<div class="image-card effect-3">
<img src="https://source.unsplash.com/random/600x400?animal" alt="动物世界">
<div class="image-overlay">
<h3 class="image-title">动物王国</h3>
<p class="image-desc">了解各种野生动物的生活习性</p>
<a href="#" class="image-btn">查看详情</a>
</div>
</div>
<!-- 特效4 - 从左侧滑入 -->
<div class="image-card effect-4">
<img src="https://source.unsplash.com/random/600x400?food" alt="美食佳肴">
<div class="image-overlay">
<h3 class="image-title">美食天堂</h3>
<p class="image-desc">品尝世界各地的美味佳肴</p>
<a href="#" class="image-btn">查看详情</a>
</div>
</div>
<!-- 特效5 - 中心放大 -->
<div class="image-card effect-5">
<img src="https://source.unsplash.com/random/600x400?travel" alt="旅行探险">
<div class="image-overlay">
<h3 class="image-title">旅行探险</h3>
<p class="image-desc">开启一段难忘的旅程</p>
<a href="#" class="image-btn">查看详情</a>
</div>
</div>
<!-- 特效6 - 旋转效果 -->
<div class="image-card effect-6">
<img src="https://source.unsplash.com/random/600x400?art" alt="艺术创作">
<div class="image-overlay">
<h3 class="image-title">艺术创作</h3>
<p class="image-desc">欣赏世界各地的艺术作品</p>
<a href="#" class="image-btn">查看详情</a>
</div>
</div>
<!-- 特效7 - 半透明覆盖 -->
<div class="image-card effect-7">
<img src="https://source.unsplash.com/random/600x400?sport" alt="体育运动">
<div class="image-overlay">
<h3 class="image-title">体育运动</h3>
<p class="image-desc">感受运动的激情与活力</p>
<a href="#" class="image-btn">查看详情</a>
</div>
</div>
<!-- 特效8 - 对角线滑入 -->
<div class="image-card effect-8">
<img src="https://source.unsplash.com/random/600x400?technology" alt="科技创新">
<div class="image-overlay">
<h3 class="image-title">科技创新</h3>
<p class="image-desc">探索科技发展的前沿</p>
<a href="#" class="image-btn">查看详情</a>
</div>
</div>
</div>
</div>
</body>
</html>
CSS3鼠标滑过图片文字动画特效
于 2025-06-25 16:25:27 首次发布