示例工程 39-nesting
39-nesting/demo-01-card/style.css
点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。
:root {
--border: #e2e8f0;
--surface: #ffffff;
--text: #0f172a;
--muted: #64748b;
--primary: #2563eb;
--soft: #eff6ff;
--featured: #f5f3ff;
--shadow: 0 8px 24px rgb(15 23 42 / 12%);
}
body {
margin: 0;
padding: 32px;
display: flex;
flex-wrap: wrap;
gap: 16px;
background: #f8fafc;
color: var(--text);
font-family: system-ui, sans-serif;
line-height: 1.7;
}
.card {
display: flex;
flex-direction: column;
width: 240px;
overflow: hidden;
border: 1px solid var(--border);
border-radius: 12px;
background: var(--surface);
transition: transform 180ms ease-out, box-shadow 180ms ease-out;
& .media {
height: 96px;
background: linear-gradient(135deg, #2563eb, #7c3aed);
&.alt {
background: linear-gradient(135deg, #0ea5e9, #2563eb);
}
}
& .body {
display: flex;
flex: 1 1 auto;
flex-direction: column;
gap: 4px;
padding: 14px;
}
& .badge {
align-self: flex-start;
padding: 1px 8px;
border-radius: 999px;
background: var(--soft);
color: var(--primary);
font-size: 11px;
}
& .title {
margin: 0;
font-size: 16px;
}
& .desc {
flex: 1 1 auto;
margin: 0;
color: var(--muted);
font-size: 13px;
}
& .link {
margin-top: 8px;
color: var(--primary);
font-size: 13px;
text-decoration: none;
&:hover,
&:focus-visible {
text-decoration: underline;
}
}
&.featured {
border-color: var(--primary);
background: var(--featured);
}
@media (hover: hover) {
&:hover {
transform: translateY(-3px);
box-shadow: var(--shadow);
}
}
}