代码如下:
<!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 {
font-family: 'Arial', sans-serif;
background-color: #f0f2f5;
margin: 0;
padding: 20px;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
.container {
max-width: 1000px;
margin: 0 auto;
text-align: center;
}
h1 {
color: #333;
margin-bottom: 30px;
text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
}
/* 棋盘样式 */
.chessboard {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 15px;
perspective: 1000px;
}
.tile {
position: relative;
width: 100%;
height: 180px;
transform-style: preserve-3d;
transition: transform 0.6s ease;
cursor: pointer;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}
.tile:hover {
transform: rotateY(180deg);
}
.tile-front, .tile-back {
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
border-radius: 8px;
overflow: hidden;
}
.tile-front img {
width: 100%;
height: 100%;
object-fit: cover;
}
.tile-front {
background-color: #fff;
display: flex;
justify-content: center;
align-items: center;
}
.tile-back {
background: linear-gradient(135deg, #6e8efb, #a777e3);
color: white;
transform: rotateY(180deg);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 15px;
box-sizing: border-box;
}
.tile-back h3 {
margin-top: 0;
font-size: 18px;
}
.tile-back p {
font-size: 14px;
margin-bottom: 10px;
}
.tile-back a {
color: #fff;
background-color: rgba(255,255,255,0.2);
padding: 5px 10px;
border-radius: 4px;
text-decoration: none;
transition: background-color 0.3s;
}
.tile-back a:hover {
background-color: rgba(255,255,255,0.3);
}
/* 响应式设计 */
@media (max-width: 768px) {
.chessboard {
grid-template-columns: repeat(2, 1fr);
}
}
@media (max-width: 480px) {
.chessboard {
grid-template-columns: 1fr;
}
}
/* 页脚样式 */
.footer {
margin-top: 40px;
color: #666;
font-size: 14px;
}
.footer a {
color: #6e8efb;
text-decoration: none;
}
</style>
</head>
<body>
<div class="container">
<h1>CSS3图片棋盘动画特效</h1>
<div class="chessboard">
<!-- 棋盘格子1 -->
<div class="tile">
<div class="tile-front">
<img src="https://picsum.photos/300/300?random=1" alt="示例图片1">
</div>
<div class="tile-back">
<h3>创意设计</h3>
<p>探索更多设计灵感</p>
</div>
</div>
<!-- 棋盘格子2 -->
<div class="tile">
<div class="tile-front">
<img src="https://picsum.photos/300/300?random=2" alt="示例图片2">
</div>
<div class="tile-back">
<h3>动画效果</h3>
<p>CSS3强大动画功能</p>
<a href="#">了解更多</a>
</div>
</div>
<!-- 棋盘格子3 -->
<div class="tile">
<div class="tile-front">
<img src="https://picsum.photos/300/300?random=3" alt="示例图片3">
</div>
<div class="tile-back">
<h3>交互体验</h3>
<p>增强用户参与感</p>
<a href="#">了解更多</a>
</div>
</div>
<!-- 棋盘格子4 -->
<div class="tile">
<div class="tile-front">
<img src="https://picsum.photos/300/300?random=4" alt="示例图片4">
</div>
<div class="tile-back">
<h3>响应式设计</h3>
<p>适配各种设备</p>
<a href="#">了解更多</a>
</div>
</div>
</div>
<div class="footer">
</div>
</div>
</body>
</html>