<!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 {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: #f0f0f0;
font-family: 'Arial', sans-serif;
}
.container {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 40px;
padding: 40px;
max-width: 1200px;
}
.image-box {
position: relative;
width: 300px;
height: 400px;
overflow: hidden;
border-radius: 10px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}
.image-box img {
width: 100%;
height: 100%;
object-fit: cover;
transition: transform 0.5s;
}
.image-box:hover img {
transform: scale(1.05);
}
.image-box::before,
.image-box::after {
content: '';
position: absolute;
width: 0;
height: 0;
border: 2px solid transparent;
transition: all 0.5s ease;
z-index: 2;
}
.image-box::before {
top: 0;
left: 0;
border-top-color: #ff4757;
border-left-color: #ff4757;
}
.image-box::after {
bottom: 0;
right: 0;
border-bottom-color: #ff4757;
border-right-color: #ff4757;
}
.image-box:hover::before,
.image-box:hover::after {
width: 100%;
height: 100%;
}
.image-box .content {
position: absolute;
bottom: -100%;
left: 0;
width: 100%;
padding: 20px;
background: rgba(0, 0, 0, 0.7);
color: #fff;
transition: bottom 0.5s;
z-index: 1;
}
.image-box:hover .content {
bottom: 0;
}
.image-box .content h3 {
margin-bottom: 10px;
font-size: 24px;
color: #ff4757;
}
.image-box .content p {
font-size: 16px;
line-height: 1.5;
}
.credit {
position: fixed;
bottom: 20px;
color: #333;
font-size: 14px;
}
.credit a {
color: #ff4757;
text-decoration: none;
}
.title {
position: fixed;
top: 20px;
color: #333;
font-size: 28px;
font-weight: bold;
text-align: center;
}
</style>
</head>
<body>
<div class="title">CSS3悬停图片线条边框动画</div>
<div class="container">
<div class="image-box">
<img src="https://source.unsplash.com/random/600x800?nature" alt="Nature">
<div class="content">
<h3>自然风光</h3>
<p>探索大自然的美丽与神奇,感受地球最原始的魅力。</p>
</div>
</div>
<div class="image-box">
<img src="https://source.unsplash.com/random/600x800?city" alt="City">
<div class="content">
<h3>城市景观</h3>
<p>现代都市的繁华景象,人类文明的集中体现。</p>
</div>
</div>
<div class="image-box">
<img src="https://source.unsplash.com/random/600x800?animal" alt="Animal">
<div class="content">
<h3>野生动物</h3>
<p>地球上的奇妙生物,与我们共享这个星球。</p>
</div>
</div>
</div>
</body>
</html>
CSS3悬停图片线条边框动画特效
于 2025-06-23 14:19:35 首次发布
699

被折叠的 条评论
为什么被折叠?



