示例工程 34-transforms
34-transforms/demo-01-basic/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; }
#on { 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;
}
#on:checked + h1 + p + label {
border-color: #2563eb;
background: #2563eb;
color: #ffffff;
}
#on:focus-visible + h1 + p + label {
outline: 2px solid #2563eb;
outline-offset: 2px;
}
.grid {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 24px;
max-width: 760px;
margin-top: 18px;
}
.cell {
display: grid;
place-items: center;
min-height: 130px;
border: 1px dashed #cbd5e1;
border-radius: 8px;
background: #ffffff;
}
.box {
display: grid;
place-items: center;
width: 100px;
height: 60px;
border-radius: 6px;
background: #2563eb;
color: #ffffff;
font-size: 10px;
font-family: ui-monospace, monospace;
transition: transform 300ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
#on:checked ~ .grid .t { transform: translateY(-10px); }
#on:checked ~ .grid .r { transform: rotate(-10deg); }
#on:checked ~ .grid .s { transform: scale(1.15); }
#on:checked ~ .grid .k { transform: skew(-10deg); }
@media (max-width: 640px) {
.grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: reduce) {
.box { transition: none; }
}