示例工程 16-grid-basics
16-grid-basics/demo-02-auto-fit/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;
}
h2 {
margin: 18px 0 6px;
font-size: 13px;
color: #64748b;
}
.grid {
display: grid;
gap: 10px;
max-width: 420px;
padding: 10px;
border: 1px dashed #cbd5e1;
border-radius: 8px;
background: #ffffff;
}
.three {
grid-template-columns: repeat(3, 1fr);
}
.auto {
grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}
.card {
display: grid;
place-items: center;
min-height: 64px;
border-radius: 6px;
background: #2563eb;
color: #ffffff;
font-size: 12px;
font-family: ui-monospace, monospace;
}