示例工程 17-grid-areas
17-grid-areas/app/style.css
点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。
*,
*::before,
*::after {
box-sizing: border-box;
}
body,
h1,
h2,
p,
ol,
ul,
pre {
margin: 0;
padding: 0;
}
body {
min-height: 100vh;
background: #f8fafc;
color: #0f172a;
font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
line-height: 1.7;
}
/* 页面骨架:三列三行,区域名描述位置 */
.app {
display: grid;
grid-template-areas:
"header header header"
"sidebar main aside"
"footer footer footer";
grid-template-columns: 200px minmax(0, 1fr) 200px;
grid-template-rows: auto minmax(0, 1fr) auto;
gap: 16px;
min-height: 100vh;
padding: 16px;
}
.app-header {
grid-area: header;
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 16px;
padding: 12px 20px;
border: 1px solid #e2e8f0;
border-radius: 12px;
background: #ffffff;
}
.brand {
font-size: 13px;
font-weight: 700;
letter-spacing: 0.16em;
text-decoration: none;
color: #0f172a;
}
.app-header nav {
display: flex;
gap: 16px;
margin-inline-start: auto;
}
.app-header nav a {
color: #64748b;
font-size: 13px;
text-decoration: none;
}
.app-header nav a[aria-current="page"],
.app-header nav a:hover,
.app-header nav a:focus-visible {
color: #2563eb;
}
.app-sidebar {
grid-area: sidebar;
align-self: start;
padding: 16px;
border: 1px solid #e2e8f0;
border-radius: 12px;
background: #ffffff;
}
.app-sidebar h2,
.app-aside h2 {
font-size: 13px;
color: #64748b;
}
.app-sidebar ol {
margin-top: 8px;
padding-inline-start: 18px;
font-size: 13px;
}
.app-sidebar li + li {
margin-top: 4px;
}
.app-sidebar a {
color: #334155;
text-decoration: none;
}
.app-sidebar a:hover,
.app-sidebar a:focus-visible {
color: #2563eb;
}
.app-main {
grid-area: main;
display: flex;
flex-direction: column;
gap: 16px;
min-width: 0;
}
.app-aside {
grid-area: aside;
align-self: start;
padding: 16px;
border: 1px solid #e2e8f0;
border-radius: 12px;
background: #ffffff;
}
.app-aside p {
margin-top: 8px;
color: #64748b;
font-size: 12px;
}
.app-footer {
grid-area: footer;
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
gap: 8px;
padding: 12px 20px;
border: 1px solid #e2e8f0;
border-radius: 12px;
background: #ffffff;
color: #64748b;
font-size: 12px;
}
.eyebrow {
color: #64748b;
font-size: 11px;
letter-spacing: 0.18em;
}
h1 {
margin: 4px 0 8px;
font-size: clamp(28px, 4vw, 38px);
line-height: 1.15;
}
.lead {
color: #334155;
font-size: 15px;
}
.panel {
padding: 20px;
border: 1px solid #e2e8f0;
border-radius: 12px;
background: #ffffff;
}
.panel h2 {
font-size: 17px;
}
.panel p {
margin-top: 8px;
color: #334155;
font-size: 14px;
}
/* 字符地图演示 */
.blueprint {
display: grid;
grid-template-areas:
"a a b"
"c d d";
grid-template-columns: repeat(3, minmax(0, 1fr));
grid-template-rows: 64px 64px;
gap: 8px;
margin-top: 12px;
padding: 8px;
border: 1px dashed #cbd5e1;
border-radius: 10px;
background: #f8fafc;
}
.bp {
display: grid;
place-items: center;
border-radius: 8px;
color: #ffffff;
font-size: 12px;
font-family: ui-monospace, Menlo, monospace;
}
.bp.a { grid-area: a; background: #2563eb; }
.bp.b { grid-area: b; background: #7c3aed; }
.bp.c { grid-area: c; background: #db2777; }
.bp.d { grid-area: d; background: #0f172a; }
pre {
margin-top: 12px;
padding: 14px;
overflow-x: auto;
border-radius: 10px;
background: #0f172a;
color: #e2e8f0;
font-size: 12px;
line-height: 1.6;
}
code {
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.rules {
margin-top: 10px;
padding-inline-start: 20px;
color: #334155;
font-size: 14px;
}
.rules li + li {
margin-top: 6px;
}
.rules code {
padding: 1px 4px;
border-radius: 4px;
background: #f1f5f9;
color: #1e40af;
font-size: 13px;
}
@media (max-width: 820px) {
.app {
grid-template-areas:
"header"
"main"
"sidebar"
"aside"
"footer";
grid-template-columns: minmax(0, 1fr);
grid-template-rows: auto;
padding: 12px;
gap: 12px;
}
.app-header nav {
margin-inline-start: 0;
}
}