示例工程 18-grid-patterns
18-grid-patterns/app/style.css
点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。
*,
*::before,
*::after {
box-sizing: border-box;
}
body,
h1,
h2,
h3,
p {
margin: 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;
}
.site-header {
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
gap: 12px;
padding: 16px 24px;
border-bottom: 1px solid #e2e8f0;
background: #ffffff;
}
.brand {
font-size: 12px;
font-weight: 700;
letter-spacing: 0.14em;
}
.site-header nav {
display: flex;
flex-wrap: wrap;
gap: 14px;
}
.site-header nav a {
color: #64748b;
font-size: 13px;
text-decoration: none;
}
.site-header nav a:hover,
.site-header nav a:focus-visible {
color: #2563eb;
}
.page {
width: min(100% - 40px, 900px);
margin: 0 auto;
padding: 36px 0 60px;
}
.eyebrow {
color: #64748b;
font-size: 11px;
letter-spacing: 0.18em;
}
h1 {
margin: 6px 0 10px;
font-size: clamp(28px, 5vw, 40px);
line-height: 1.15;
}
.lead {
color: #334155;
font-size: 16px;
}
.panel {
margin-top: 18px;
padding: 22px;
border: 1px solid #e2e8f0;
border-radius: 16px;
background: #ffffff;
}
h2 {
font-size: 18px;
}
.panel > p {
margin-top: 6px;
color: #334155;
font-size: 13px;
}
/* 1. 图片墙 */
.gallery {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
grid-auto-rows: 84px;
grid-auto-flow: row dense;
gap: 8px;
margin-top: 12px;
}
.shot {
border-radius: 8px;
background: #cbd5e1;
}
.shot span {
display: grid;
place-items: center;
height: 100%;
color: #ffffff;
font-size: 11px;
letter-spacing: 0.12em;
}
.feature {
grid-column: span 2;
grid-row: span 2;
background: linear-gradient(135deg, #2563eb, #7c3aed);
}
.s1 { background: linear-gradient(135deg, #0ea5e9, #2563eb); }
.s2 { background: linear-gradient(135deg, #7c3aed, #db2777); }
.s3 { background: linear-gradient(135deg, #f59e0b, #db2777); }
.s4 { background: linear-gradient(135deg, #0f172a, #475569); }
.s5 { background: linear-gradient(135deg, #10b981, #0ea5e9); }
.s6 { background: linear-gradient(135deg, #db2777, #f59e0b); }
.s7 { background: linear-gradient(135deg, #475569, #0f172a); }
/* 2. 日历 */
.cal {
display: grid;
grid-template-columns: repeat(7, minmax(0, 1fr));
gap: 4px;
margin-top: 12px;
padding: 8px;
border: 1px solid #e2e8f0;
border-radius: 12px;
background: #f8fafc;
}
.dow {
padding: 4px 0;
color: #64748b;
font-size: 11px;
text-align: center;
}
.day,
.pad {
display: grid;
place-items: center;
min-height: 36px;
border-radius: 6px;
font-size: 12px;
}
.day {
background: #ffffff;
color: #0f172a;
}
.pad {
background: transparent;
}
.today {
background: #2563eb;
color: #ffffff;
font-weight: 700;
}
/* 3. 瀑布流 */
.masonry {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
grid-auto-rows: 8px;
gap: 8px;
margin-top: 12px;
}
.note {
display: flex;
flex-direction: column;
justify-content: space-between;
padding: 12px;
border-radius: 10px;
background: #eff6ff;
color: #1e40af;
font-size: 16px;
font-weight: 700;
}
.note small {
color: #64748b;
font-size: 10px;
font-weight: 400;
font-family: ui-monospace, Menlo, monospace;
}
.short { grid-row: span 10; }
.mid { grid-row: span 13; }
.tall { grid-row: span 16; }
.note:nth-child(2) { background: #f5f3ff; color: #6d28d9; }
.note:nth-child(3) { background: #fdf2f8; color: #be185d; }
.note:nth-child(5) { background: #ecfdf5; color: #047857; }
/* 4. 价格表 */
.plans {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
align-items: stretch;
gap: 12px;
margin-top: 12px;
}
.plan {
display: flex;
flex-direction: column;
gap: 6px;
padding: 18px;
border: 1px solid #e2e8f0;
border-radius: 12px;
background: #f8fafc;
}
.plan h3 {
font-size: 14px;
}
.price {
font-size: 26px;
font-weight: 700;
line-height: 1.2;
}
.plan > p:not(.price) {
flex: 1 1 auto;
color: #64748b;
font-size: 12px;
}
.plan button {
min-height: 44px;
margin-top: auto;
border: 1px solid #cbd5e1;
border-radius: 8px;
background: #ffffff;
color: #0f172a;
font-size: 12px;
}
.featured {
border-color: #2563eb;
background: #ffffff;
box-shadow: 0 8px 24px rgb(37 99 235 / 12%);
}
.featured button {
border-color: #2563eb;
background: #2563eb;
color: #ffffff;
}
.site-footer {
padding: 20px 24px 36px;
color: #64748b;
font-size: 12px;
text-align: center;
}
@media (max-width: 720px) {
.site-header {
padding: 12px 18px;
}
.page {
width: min(100% - 28px, 900px);
padding: 24px 0 44px;
}
.panel {
padding: 16px;
}
.gallery {
grid-template-columns: repeat(2, minmax(0, 1fr));
grid-auto-rows: 76px;
}
.masonry {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.plans {
grid-template-columns: minmax(0, 1fr);
}
}