如何 - 翻转卡片
了解如何使用 CSS 创建翻转卡片。
将鼠标悬停在下面的图像上

John Doe
建筑师与工程师
我们爱那个人
如何创建翻转卡片
步骤 1) 添加 HTML
示例
<div class="flip-card">
<div class="flip-card-inner">
<div class="flip-card-front">
<img src="img_avatar.png" alt="头像" style="width:300px;height:300px;">
</div>
<div class="flip-card-back">
<h1>John Doe</h1>
<p>建筑师与工程师</p>
<p>我们爱那个人</p>
</div>
</div>
</div>
步骤 2) 添加 CSS
示例
/* 翻转卡片容器 - 设置你想要的宽度和高度。我们添加了边框属性来演示翻转本身会超出盒子(如果不想看到 3D 效果,请删除 perspective)*/
.flip-card {
background-color: transparent;
width: 300px;
height: 200px;
border: 1px solid #f1f1f1;
perspective: 1000px; /* 如果不想看到 3D 效果,请删除此行 */
}
/* 此容器是定位正面和背面所必需的 */
.flip-card-inner {
position: relative;
width: 100%;
height: 100%;
text-align: center;
transition: transform 0.8s;
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%;
-webkit-backface-visibility: hidden; /* Safari */
backface-visibility: hidden;
}
/* 样式正面(作为图像缺失时的后备)*/
.flip-card-front {
background-color: #bbb;
color: black;
}
/* 样式背面 */
.flip-card-back {
background-color: dodgerblue;
color: white;
transform: rotateY(180deg);
}
自己动手试一试 »