示例工程 34-transforms
34-transforms/demo-02-3d/style.css
点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。
body {
margin: 0;
padding: 32px;
background: #f8fafc;
color: #0f172a;
font-family: system-ui, sans-serif;
line-height: 1.7;
}
h1 { margin: 0 0 8px; font-size: 26px; }
#flip { position: absolute; opacity: 0; width: 1px; height: 1px; }
label {
display: inline-flex;
margin-top: 8px;
padding: 6px 14px;
border: 1px solid #e2e8f0;
border-radius: 999px;
background: #ffffff;
color: #64748b;
font-size: 12px;
cursor: pointer;
}
#flip:checked + h1 + p + label {
border-color: #2563eb;
background: #2563eb;
color: #ffffff;
}
.scene {
width: 280px;
height: 180px;
margin-top: 20px;
perspective: 900px;
}
.card {
position: relative;
width: 100%;
height: 100%;
transform-style: preserve-3d;
transition: transform 700ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
#flip:checked ~ .scene .card {
transform: rotateY(180deg);
}
.face {
position: absolute;
inset: 0;
display: grid;
place-content: center;
gap: 4px;
border-radius: 12px;
text-align: center;
backface-visibility: hidden;
}
.front {
border: 1px solid #e2e8f0;
background: #ffffff;
}
.back {
transform: rotateY(180deg);
background: linear-gradient(135deg, #2563eb, #7c3aed);
color: #ffffff;
}
strong {
font-size: 10px;
font-family: ui-monospace, monospace;
letter-spacing: 0.16em;
}
span { font-size: 16px; font-weight: 600; }
@media (prefers-reduced-motion: reduce) {
.card { transition: none; }
}