团队一起做东西的人
3D flip card
3D 卡片翻转
A card flips around its vertical axis on hover or focus to show what is on the back.
Also searched as: 鼠标放上去卡片翻到背面, 卡片正反两面翻转, 像翻牌一样转过来的卡片, 翻过来看背面的介绍
- Placement
- Card list
- Mood
- Playful, Refined
- Trigger
- 悬停
- Site types
- 个人网站, 作品集, 品牌官网
How it works & accessibility
The outer element takes the pointer and focus and never moves; the inner layer turns rotate y 180deg with a CSS transition, the front and back share one grid cell so the card is as tall as the taller face, the back starts turned 180deg and both faces hide their backs; keyboard focus and a tap on touch screens flip it too, and with reduced motion it switches faces instantly.
Best for: Card list (悬停).
Reduced motion: 不转,直接换成背面(没有翻转的过程)
Mobile & touch: 手机不能悬停:点一下卡片(卡片能获得焦点)翻过来,点别处翻回去
Key parameters
| Parameter | Key | Default | Range | Notes |
|---|---|---|---|---|
| 翻转时长 | duration | 600ms | — | — |
| 缓动 | easing | cubic-bezier(0.4, 0, 0.2, 1) | — | — |
Ready-to-paste AI prompt
Add “3D flip card” to the card list in my project: The outer element takes the pointer and focus and never moves; the inner layer turns rotate y 180deg with a CSS transition, the front and back share one grid cell so the card is as tall as the taller face, the back starts turned 180deg and both faces hide their backs; keyboard focus and a tap on touch screens flip it too, and with reduced motion it switches faces instantly.
Parameters: duration: 600ms, easing: cubic-bezier(0.4, 0, 0.2, 1).
Preserve existing content and layout. Respect prefers-reduced-motion by showing the final state. Content must remain visible if JavaScript fails or is disabled.
Reference: https://donglang.linter.top/effects/flip-card.md (canonical specification and reference code).Dependency-free reference code
CSS
/* 3D 卡片翻转(3D flip card)· 只用 CSS,不需要脚本。正面看封面,鼠标停上去、键盘选中时绕竖轴翻过来露出背面;离开时翻回去。
同类效果见 StyleKit 的 flip-card、Animation Handbook 的 flip-card-3d(都是 MIT);本站按通用做法自己实现,没有复制代码。
结构:.flip(外层,接收鼠标和焦点,不转)> .flip-body(转的那一层)> .flip-front、.flip-back(正面、背面)。
- 转的是里面那一层,外层不动:翻的时候鼠标不会滑出去,不会一翻一停。
- 正面、背面叠在同一格里(grid),卡片的高度按两面里高的那面算,不用写死高度;背面先转 180 度贴在背后,
两面都设成背朝人时不显示(backface-visibility: hidden)。用 rotate 属性,不碰元素的 transform。
- 翻到一半时用 visibility 交换可访问的面:隐藏面不进入读屏,也不能获得键盘焦点;两面仍参与高度计算。
- 键盘:外层要能获得焦点(它本身是链接就行,不是的话写 tabindex="0"),选中时翻过来;背面里的链接用 Tab 选到时卡片也是翻着的。
- 手机不能悬停:点一下卡片(获得焦点)翻过来,点别处(失去焦点)翻回去。
- 想让某一张一直翻着,加 class="is-flipped"。
- --flip-duration:翻转时长;--flip-easing:缓动。两面的底色、圆角、内边距写在下面的 :where() 里,按自己的网站改。
- 开启"减少动态"时:不转,直接换成背面(没有翻转的过程)。 */
/* 默认值写在 :where() 里(不占优先级):网站自己的样式不管写在这段代码前面还是后面,都用网站自己的 */
:where(.flip) {
--flip-duration: 600ms;
--flip-easing: cubic-bezier(0.4, 0, 0.2, 1);
display: block;
}
.flip {
perspective: 1000px;
}
.flip-body {
position: relative;
display: grid;
transform-style: preserve-3d;
transition: rotate var(--flip-duration) var(--flip-easing);
}
.flip-front,
.flip-back {
grid-area: 1 / 1;
backface-visibility: hidden;
-webkit-backface-visibility: hidden;
transition: visibility 0s linear calc(var(--flip-duration) / 2);
}
.flip-front { visibility: visible; }
.flip-back { visibility: hidden; }
:where(.flip-front, .flip-back) {
box-sizing: border-box;
padding: 16px;
border-radius: 12px;
background: #fff;
}
:where(.flip-back) {
background: #f1f3f8;
}
.flip-back {
rotate: y 180deg;
}
@media (hover: hover) {
.flip:hover .flip-body { rotate: y 180deg; }
.flip:hover .flip-front { visibility: hidden; }
.flip:hover .flip-back { visibility: visible; }
}
.flip:focus-within .flip-body,
.flip.is-flipped .flip-body {
rotate: y 180deg;
}
.flip:focus-within .flip-front,
.flip.is-flipped .flip-front { visibility: hidden; }
.flip:focus-within .flip-back,
.flip.is-flipped .flip-back { visibility: visible; }
@media (prefers-reduced-motion: reduce) {
.flip-body, .flip-front, .flip-back { transition: none; }
}HTML
<!-- 3D 卡片翻转:外层 .flip 接收鼠标和焦点(不是链接的话写 tabindex="0"),里面 .flip-body 叠着正面和背面 -->
<div class="flip" tabindex="0">
<div class="flip-body">
<div class="flip-front">
<h3>北煜ii</h3>
<p>独立设计师</p>
</div>
<div class="flip-back">
<p>做网站和小工具,喜欢把想法做成能用的东西。</p>
<a href="/about/">了解更多</a>
</div>
</div>
</div>