示例工程 17-grid-areas
17-grid-areas/demo-02-relayout/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: 0 0 6px;
font-size: 13px;
color: #64748b;
}
.wrap {
display: flex;
flex-wrap: wrap;
gap: 20px;
margin-top: 16px;
}
.layout {
display: grid;
width: 340px;
gap: 10px;
padding: 10px;
border: 1px dashed #cbd5e1;
border-radius: 10px;
background: #ffffff;
}
.wide {
grid-template-areas: "nav main aside";
grid-template-columns: 64px minmax(0, 1fr) 64px;
grid-template-rows: 180px;
}
.narrow {
grid-template-areas:
"main"
"nav"
"aside";
grid-template-columns: minmax(0, 1fr);
grid-template-rows: 140px 48px 48px;
}
.box {
display: grid;
place-items: center;
border-radius: 8px;
color: #ffffff;
font-size: 12px;
font-family: ui-monospace, monospace;
}
.nav { grid-area: nav; background: #7c3aed; }
.main { grid-area: main; background: #0f172a; }
.aside { grid-area: aside; background: #db2777; }