关于 elite-layouts
用于选择和实现现代网页布局模式的参考技能,面向设计师与开发者。内容涵盖网格、横向滚动、粘性视差、容器查询及响应式布局,并考虑无障碍和性能。
主要功能
- 01Bento 与编辑式网格模式
- 02横向滚动布局
- 03粘性与视差区块
- 04容器查询指南
- 05响应式与内容感知布局
- 06无障碍与性能实践
适用场景
- 01规划落地页布局
- 02构建响应式商品网格
- 03设计仪表板面板与组件
- 04制作编辑式或杂志页面
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ rshvr/ elite-web-design --skill elite-layouts安装后在 Claude Code 中输入/elite-layouts确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
references/bento-grids.mdcontainer-queries.mdeditorial-patterns.mdhorizontal-scroll.mdsticky-parallax.md详细介绍
精选布局
定义现代获奖网站的高级布局模式。
快速参考
| 主题 | 参考文件 |
|---|---|
| Bento 网格 | bento-grids.md |
| 横向滚动 | horizontal-scroll.md |
| 粘性与视差 | sticky-parallax.md |
| 容器查询 | container-queries.md |
| 编辑类布局模式 | editorial-patterns.md |
布局决策框架
按项目类型
| 项目 | 主要布局 | 关键模式 |
|---|---|---|
| 作品集 | Bento + 横向滚动 | 特色作品、案例研究 |
| 电子商务 | 容器查询 | 产品网格、响应式卡片 |
| 落地页 | 粘性视差 | Hero → 功能特性 → CTA 流程 |
| 仪表盘 | Bento + 容器 | 可调整大小的面板、小组件 |
| 博客/杂志 | 非对称网格 | 编辑风格、视觉层次 |
| 代理机构 | 横向滚动 + Bento | 沉浸式、探索式 |
模式选择
Need adaptive components? → Container Queries
Need visual interest/variety? → Bento Grids
Need immersive storytelling? → Horizontal Scroll
Need depth/layering? → Sticky Parallax
Need all of the above? → Combine strategically
核心网格系统
12 列基础网格
.container {
--columns: 12;
--gutter: clamp(1rem, 2vw, 2rem);
--margin: clamp(1rem, 5vw, 6rem);
display: grid;
grid-template-columns:
[full-start] var(--margin)
[content-start] repeat(var(--columns), 1fr)
[content-end] var(--margin)
[full-end];
gap: var(--gutter);
}
/* Full-bleed items */
.full-bleed {
grid-column: full-start / full-end;
}
/* Content-width items */
.content {
grid-column: content-start / content-end;
}
/* Responsive columns */
@media (max-width: 768px) {
.container {
--columns: 4;
--margin: 1rem;
}
}
跨列工具类
/* Column spans */
.col-span-1 {
grid-column: span 1;
}
.col-span-2 {
grid-column: span 2;
}
.col-span-3 {
grid-column: span 3;
}
.col-span-4 {
grid-column: span 4;
}
.col-span-6 {
grid-column: span 6;
}
.col-span-8 {
grid-column: span 8;
}
.col-span-12 {
grid-column: span 12;
}
/* Row spans */
.row-span-2 {
grid-row: span 2;
}
.row-span-3 {
grid-row: span 3;
}
/* Responsive adjustments */
@media (max-width: 768px) {
.col-span-6,
.col-span-4 {
grid-column: span 4; /* Full width on mobile */
}
}
Bento 网格快速入门
.bento-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-auto-rows: minmax(200px, auto);
gap: 1rem;
}
/* Feature item - large */
.bento-item.featured {
grid-column: span 2;
grid-row: span 2;
}
/* Tall item */
.bento-item.tall {
grid-row: span 2;
}
/* Wide item */
.bento-item.wide {
grid-column: span 2;
}
@media (max-width: 768px) {
.bento-grid {
grid-template-columns: repeat(2, 1fr);
}
.bento-item.featured,
.bento-item.wide {
grid-column: span 2;
}
}
有关高级模式,请参阅 bento-grids.md。
横向滚动快速入门
纯 CSS(scroll-snap)
.horizontal-scroll {
display: flex;
overflow-x: auto;
scroll-snap-type: x mandatory;
scrollbar-width: none;
}
.horizontal-scroll::-webkit-scrollbar {
display: none;
}
.horizontal-section {
flex: 0 0 100vw;
min-width: 100vw;
height: 100vh;
scroll-snap-align: start;
}
GSAP ScrollTrigger(固定定位)
gsap.to(".horizontal-track", {
x: () =>
-(
document.querySelector(".horizontal-track").scrollWidth -
window.innerWidth
),
ease: "none",
scrollTrigger: {
trigger: ".horizontal-container",
pin: true,
scrub: 1,
end: () => `+=${document.querySelector(".horizontal-track").scrollWidth}`,
},
});
有关完整模式,请参阅 horizontal-scroll.md。
粘性视差快速入门
CSS 粘性区段
.sticky-container {
position: relative;
}
.sticky-section {
position: sticky;
top: 0;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
/* Stack sections with z-index */
.sticky-section:nth-child(1) {
z-index: 1;
background: var(--color-bg-1);
}
.sticky-section:nth-child(2) {
z-index: 2;
background: var(--color-bg-2);
}
.sticky-section:nth-child(3) {
z-index: 3;
background: var(--color-bg-3);
}
GSAP 固定定位并添加动画
gsap
.timeline({
scrollTrigger: {
trigger: ".pinned-section",
pin: true,
scrub: 1,
start: "top top",
end: "+=200%",
},
})
.from(".content-1", { opacity: 0, y: 50 })
.from(".content-2", { opacity: 0, y: 50 })
.from(".content-3", { opacity: 0, y: 50 });
有关分层效果,请参阅 sticky-parallax.md。
容器查询快速入门
/* Define containment */
.card-container {
container-type: inline-size;
container-name: card;
}
/* Base styles */
.card {
display: flex;
flex-direction: column;
padding: 1rem;
}
/* Respond to container width */
@container card (min-width: 400px) {
.card {
flex-direction: row;
gap: 1.5rem;
}
.card-image {
flex: 0 0 40%;
}
}
@container card (min-width: 600px) {
.card {
padding: 2rem;
}
.card-title {
font-size: 1.5rem;
}
}
有关高级模式,请参阅 container-queries.md。
布局与动画集成
网格项动画
/* Hide items ONLY when scroll-driven animation is supported AND motion is
allowed. If either is false, items render visible by default — so Firefox
(still flag-gated in 2026) and reduced-motion users are never stranded at
opacity: 0 with no timeline to reveal them. Feature-detect view()
specifically because it's the timeline this reveal uses. */
@supports (animation-timeline: view()) {
@media (prefers-reduced-motion: no-preference) {
.grid-item {
opacity: 0;
transform: translateY(30px);
animation: revealItem linear both;
animation-timeline: view();
animation-range: entry 0% cover 30%;
}
}
}
@keyframes revealItem {
to {
opacity: 1;
transform: none;
}
}
GSAP 网格动画
gsap.from(".grid-item", {
opacity: 0,
y: 50,
stagger: {
amount: 0.8,
grid: "auto",
from: "start",
},
scrollTrigger: {
trigger: ".grid-container",
start: "top 80%",
},
});
使用 FLIP 实现布局变化
// Before layout change
const state = Flip.getState(".grid-item");
// Change layout (filter, sort, resize)
filterItems();
// Animate the change
Flip.from(state, {
duration: 0.6,
ease: "power2.inOut",
stagger: 0.05,
absolute: true,
});
响应式策略
移动优先断点
/* Mobile: 1 column */
.layout {
display: grid;
grid-template-columns: 1fr;
gap: 1rem;
padding: 1rem;
}
/* Tablet: 2 columns */
@media (min-width: 640px) {
.layout {
grid-template-columns: repeat(2, 1fr);
gap: 1.5rem;
padding: 2rem;
}
}
/* Desktop: 3+ columns */
@media (min-width: 1024px) {
.layout {
grid-template-columns: repeat(3, 1fr);
gap: 2rem;
padding: 3rem;
}
}
/* Large: 4 columns */
@media (min-width: 1280px) {
.layout {
grid-template-columns: repeat(4, 1fr);
}
}
流式布局(无断点)
/* Auto-fit columns */
.fluid-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
gap: clamp(1rem, 3vw, 2rem);
}
/* Fluid spacing */
.section {
padding-block: clamp(3rem, 10vh, 8rem);
padding-inline: clamp(1rem, 5vw, 6rem);
}
使用 :has() 实现内容感知布局
让布局根据其 内容 而不仅仅是视口做出响应。:has() 自 2023 年末起已成为所有主流浏览器的 Baseline 功能,无需回退方案。
/* Quantity queries: the grid restructures as items are added */
.card-grid {
display: grid;
grid-template-columns: 1fr;
gap: 1.5rem;
}
.card-grid:has(> :nth-child(2)) {
grid-template-columns: repeat(2, 1fr);
}
.card-grid:has(> :nth-child(4)) {
grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}
/* Give an article a sidebar only when it actually contains a figure */
.article:has(> figure) {
grid-template-columns: 1fr 320px;
}
/* Collapse a section's chrome when it has no items (empty state) */
.gallery:not(:has(.gallery-item)) {
display: none;
}
相比于使用 JavaScript 统计子元素并切换类名,更推荐这种方式——它采用声明式写法,会随 DOM 自动重新流动,且运行时开销为零。
常见布局模式
Hero + 内容网格
.hero-layout {
display: grid;
grid-template-rows: 100vh auto;
}
.hero {
display: grid;
place-items: center;
position: relative;
}
.content-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 2rem;
padding: clamp(2rem, 5vw, 4rem);
}
侧边栏 + 主内容区
.sidebar-layout {
display: grid;
grid-template-columns: minmax(250px, 300px) 1fr;
min-height: 100vh;
}
@media (max-width: 768px) {
.sidebar-layout {
grid-template-columns: 1fr;
}
.sidebar {
position: fixed;
inset: 0;
transform: translateX(-100%);
transition: transform 0.3s ease;
}
.sidebar.open {
transform: translateX(0);
}
}
瀑布流
原生瀑布流布局即将到来——Safari 26.4 于 2026 年率先支持;Chrome 和 Firefox 仍需启用实验标志,并将在 2026 年逐步稳定。语法仍在演进中(grid-template-rows: masonry 与较新的 display: grid-lanes / Item Flow 提案之间尚未定稿),因此请使用特性检测,切勿通过版本号判断,并在生产环境中保留下面的 JavaScript 回退方案。
/* Enhancement: native masonry where supported */
.masonry {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
gap: 1rem;
}
@supports (grid-template-rows: masonry) {
.masonry {
grid-template-rows: masonry; /* rows pack tightly up each column */
}
}
回退方案(当前可安全用于生产环境)
使用固定高度行和由 JavaScript 计算跨行数的网格,现在即可在所有环境中正常工作:
.masonry-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
grid-auto-rows: 10px;
gap: 1rem;
}
.masonry-item {
/* Set via JS based on content height */
grid-row-end: span var(--row-span, 20);
}
// Calculate row spans based on content
function setMasonrySpans() {
const grid = document.querySelector(".masonry-grid");
const rowHeight = 10;
const gap = 16;
grid.querySelectorAll(".masonry-item").forEach((item) => {
const content = item.querySelector(".content");
const span = Math.ceil((content.offsetHeight + gap) / (rowHeight + gap));
item.style.setProperty("--row-span", span);
});
}
性能注意事项
布局隔离
/* Isolate layout calculations */
.grid-item {
contain: layout style;
}
/* Full containment for complex items */
.complex-card {
contain: strict;
content-visibility: auto;
contain-intrinsic-size: 300px;
}
避免布局抖动
// BAD: Forces layout per item
items.forEach((item) => {
item.style.width = item.offsetWidth + 10 + "px";
});
// GOOD: Batch reads, then writes
const widths = items.map((item) => item.offsetWidth);
items.forEach((item, i) => {
item.style.width = widths[i] + 10 + "px";
});
CSS Grid 与 Flexbox
| 使用 Grid | 使用 Flexbox |
|---|---|
| 二维布局 | 一维布局 |
| 结构已知 | 项目数量未知 |
| 项目重叠 | 内容分布 |
| 杂志/Bento 布局 | 导航、卡片 |
| 复杂对齐 | 简单对齐 |
无障碍
跳过横向区段
<a href="#after-horizontal" class="skip-link">
Skip horizontal scroll section
</a>
<section class="horizontal-scroll" aria-label="Project gallery">
</section>
<div id="after-horizontal"></div>
键盘导航
// Allow arrow key navigation in horizontal scroll
horizontalContainer.addEventListener("keydown", (e) => {
if (e.key === "ArrowRight") {
horizontalContainer.scrollBy({
left: window.innerWidth,
behavior: "smooth",
});
}
if (e.key === "ArrowLeft") {
horizontalContainer.scrollBy({
left: -window.innerWidth,
behavior: "smooth",
});
}
});
播报布局变化
// For dynamic layout changes (filtering)
const liveRegion = document.getElementById("live-region");
liveRegion.textContent = `Showing ${visibleItems.length} of ${totalItems} items`;
保持阅读顺序同步
当网格布局(命名区域、order 或 grid-row/grid-column)让项目脱离其 DOM 顺序时,键盘和屏幕阅读器用户仍会按照源顺序浏览——这违反了 WCAG 2.4.3(焦点顺序)。可靠的解决方案是让 DOM 顺序与主要视觉顺序保持一致。作为渐进增强,reading-flow(Chrome 137+,2026 年仅限 Chromium)可以使焦点顺序和阅读顺序与视觉流对齐:
.bento-grid {
display: grid;
reading-flow: grid-order; /* focus follows visual grid order where supported */
}
应将其视为增强功能,而不是合理源顺序的替代方案。