先上效果
🌟 CSS卡片翻转效果不仅能够为网站增添动态的视觉效果,还能以一种新颖的方式展示信息,激发用户的探索兴趣。本文将详细介绍如何利用CSS的动画和转换特性,实现一个引人入胜的卡片翻转动画,让您的网站设计更具吸引力和现代感。
完整代码
以下是完整代码:
HTML:
<div class="flip-card"> <div class="flip-card-inner"> <div class="flip-card-front"> <h2>Front Side</h2> </div> <div class="flip-card-back"> <h2>Back Side</h2> <p>Some details here</p> </div> </div> </div>
CSS代码
.flip-card { background-color: transparent; width: 300px; height: 200px; perspective: 1000px; margin: 40px; } .flip-card-inner { position: relative; width: 100%; height: 100%; text-align: center; transition: transform 0.6s; transform-style: preserve-3d; } .flip-card:hover .flip-card-inner { transform: rotateY(180deg); } .flip-card-front, .flip-card-back { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; align-items: center; justify-content: center; border-radius: 10px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); } .flip-card-front { background-color: #bbb; color: black; } .flip-card-back { background-color: #2980b9; color: white; transform: rotateY(180deg); }