css-layout
Create or fix layouts using modern CSS Grid, Flexbox, container queries, and logical properties. Includes a Grid vs Flexbox decision tree and patterns for common layouts. Use when the user asks for a CSS layout, grid layout, flexbox layout, sidebar layout, holy grail, card grid, centering, or layout fix.
Best use case
css-layout is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Create or fix layouts using modern CSS Grid, Flexbox, container queries, and logical properties. Includes a Grid vs Flexbox decision tree and patterns for common layouts. Use when the user asks for a CSS layout, grid layout, flexbox layout, sidebar layout, holy grail, card grid, centering, or layout fix.
Teams using css-layout should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/css-layout/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How css-layout Compares
| Feature / Agent | css-layout | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Create or fix layouts using modern CSS Grid, Flexbox, container queries, and logical properties. Includes a Grid vs Flexbox decision tree and patterns for common layouts. Use when the user asks for a CSS layout, grid layout, flexbox layout, sidebar layout, holy grail, card grid, centering, or layout fix.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# css.dev — CSS Layout
You are a senior CSS layout engineer. Build or fix layouts using modern CSS. Always generate code. For the full pattern catalog, see [modern-patterns.md](../css-expert/references/modern-patterns.md). For layout anti-patterns to avoid, see [anti-patterns.md](../css-expert/references/anti-patterns.md).
## Workflow
1. **Understand the requirement** — What is the user building? A page layout, component layout, or fixing a broken one?
2. **Choose the technique** — Use the decision tree below.
3. **Write the CSS** — Follow the patterns in this skill. Use custom properties for spacing. Use logical properties.
4. **Add responsiveness** — Use container queries for component-level adaptation, media queries only for page-level shifts.
5. **Verify** — Check that the layout handles: empty states, overflow, long content, RTL, and varying viewport sizes.
## Decision Tree
```
What are you laying out?
│
├─ 2D layout (rows AND columns)?
│ └─ CSS Grid
│ ├─ Known, named regions → grid-template-areas
│ ├─ Repeating uniform items → repeat(auto-fill, minmax())
│ ├─ Children need parent's tracks → subgrid
│ └─ Component-responsive → container queries + grid
│
├─ 1D layout (single row OR column)?
│ └─ Flexbox
│ ├─ Items should wrap → flex-wrap: wrap + gap
│ ├─ Items should stay in line → flex-shrink / overflow
│ └─ Even distribution → flex: 1 or justify-content: space-between
│
├─ Centering something?
│ ├─ Single element → place-items: center (grid) or margin: auto
│ ├─ Text → text-align: center + align vertical with flexbox
│ └─ Absolute overlay → position: absolute + inset: 0 + grid place-items
│
├─ Overlapping / stacking?
│ ├─ Controlled overlap → grid with shared grid-area
│ └─ Arbitrary positioning → position: absolute (only valid use)
│
└─ Need component-level responsiveness?
└─ container-type: inline-size + @container queries
```
## Grid Patterns
### Named Grid Areas
Use when you have a semantic, named layout with distinct regions.
```css
.page {
display: grid;
grid-template:
"header header" auto
"sidebar main" 1fr
"footer footer" auto
/ minmax(200px, 300px) 1fr;
min-height: 100dvh;
}
.header { grid-area: header; }
.sidebar { grid-area: sidebar; }
.main { grid-area: main; }
.footer { grid-area: footer; }
@media (max-width: 48em) {
.page {
grid-template:
"header" auto
"main" 1fr
"sidebar" auto
"footer" auto
/ 1fr;
}
}
```
### Auto-Fill / Auto-Fit Card Grid
Use for repeating items that should fill available space.
```css
.card-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr));
gap: var(--space-m);
}
```
- `auto-fill` creates empty tracks if space remains — use when you want consistent column widths.
- `auto-fit` collapses empty tracks — use when you want items to stretch to fill the row.
- `min(280px, 100%)` prevents overflow on small containers.
### Subgrid
Use when children need to align to the parent grid's tracks. Common for cards with aligned headers, bodies, and footers.
```css
.card-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
gap: var(--space-m);
}
.card {
display: grid;
grid-template-rows: subgrid;
grid-row: span 3;
gap: var(--space-s);
}
```
### Dense Auto-Placement
Use for masonry-like packing when items have varying sizes.
```css
.gallery {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
grid-auto-flow: dense;
gap: var(--space-xs);
}
.gallery-item--wide { grid-column: span 2; }
.gallery-item--tall { grid-row: span 2; }
```
## Flexbox Patterns
### Navigation Bar
```css
.nav {
display: flex;
align-items: center;
gap: var(--space-s);
flex-wrap: wrap;
}
.nav-spacer { margin-inline-start: auto; }
```
### Wrapping Tag List
```css
.tags {
display: flex;
flex-wrap: wrap;
gap: var(--space-2xs);
}
```
### Equal-Width Items
```css
.equal-row {
display: flex;
gap: var(--space-m);
> * { flex: 1; }
}
```
### Sticky Footer (Page Level)
```css
body {
display: flex;
flex-direction: column;
min-height: 100dvh;
}
main { flex: 1; }
```
## Centering Patterns
### Grid Centering (preferred)
```css
.center {
display: grid;
place-items: center;
}
```
### Flex Centering
```css
.center {
display: flex;
justify-content: center;
align-items: center;
}
```
### Auto-Margin Centering
```css
.center-block {
max-width: 60rem;
margin-inline: auto;
}
```
### Dialog / Overlay Centering
```css
.overlay {
position: fixed;
inset: 0;
display: grid;
place-items: center;
}
```
## Common Page Layouts
### Holy Grail
Header, footer, sidebar, and main content with the content area taking remaining space.
```css
body {
display: grid;
grid-template:
"header header" auto
"nav main" 1fr
"footer footer" auto
/ minmax(200px, 20%) 1fr;
min-height: 100dvh;
}
```
### Sidebar Layout (collapsible)
```css
.layout {
display: grid;
grid-template-columns: fit-content(300px) 1fr;
gap: var(--space-l);
}
@media (max-width: 48em) {
.layout { grid-template-columns: 1fr; }
}
```
### Content + Sidebar (intrinsic)
The sidebar takes its natural width, main content gets the rest.
```css
.with-sidebar {
display: flex;
flex-wrap: wrap;
gap: var(--space-l);
}
.with-sidebar > :first-child { flex-basis: 250px; flex-grow: 1; }
.with-sidebar > :last-child { flex-basis: 0; flex-grow: 999; min-inline-size: 60%; }
```
### Pancake Stack
```css
body {
display: grid;
grid-template-rows: auto 1fr auto;
min-height: 100dvh;
}
```
## Container Queries
Use container queries for component-level responsiveness. Media queries are for page-level layout shifts only.
### Setup
```css
.component-wrapper {
container-type: inline-size;
container-name: card;
}
```
### Responsive Card
```css
.card-wrapper {
container-type: inline-size;
}
.card {
display: grid;
grid-template-columns: 1fr;
gap: var(--space-s);
@container (inline-size >= 500px) {
grid-template-columns: 200px 1fr;
}
@container (inline-size >= 800px) {
grid-template-columns: 300px 1fr auto;
}
}
```
### Container Query Units
```css
.card-title {
font-size: clamp(1rem, 3cqi, 1.5rem);
}
```
`cqi` = 1% of the container's inline size.
## Logical Properties
Always use logical properties instead of physical ones.
| Physical | Logical |
|----------|---------|
| `width` | `inline-size` |
| `height` | `block-size` |
| `margin-left` | `margin-inline-start` |
| `margin-right` | `margin-inline-end` |
| `margin-top` | `margin-block-start` |
| `padding-left` | `padding-inline-start` |
| `top` | `inset-block-start` |
| `left` | `inset-inline-start` |
| `text-align: left` | `text-align: start` |
| `border-left` | `border-inline-start` |
```css
.element {
margin-block: var(--space-m);
padding-inline: var(--space-l);
border-inline-start: 3px solid var(--color-primary);
max-inline-size: 65ch;
}
```
## Spacing Rules
- Use `gap` for space between grid/flex children — never margin hacks.
- Use custom properties for all spacing values: `var(--space-s)`, `var(--space-m)`, etc.
- Use `clamp()` for fluid spacing that adapts without breakpoints.
- Reference the spacing scale from [modern-patterns.md](../css-expert/references/modern-patterns.md).
## Checklist Before Delivering
- [ ] No `float` used for layout
- [ ] No negative margins for spacing (use `gap`)
- [ ] All spacing uses custom properties
- [ ] Logical properties used instead of physical
- [ ] Layout handles empty content gracefully
- [ ] Long text doesn't break the layout (test with `overflow-wrap: break-word`)
- [ ] Container queries used for component-level responsiveness
- [ ] Media queries used only for page-level layout shifts
- [ ] Grid used for 2D, Flexbox for 1D
- [ ] `min()` used in `minmax()` to prevent overflow: `minmax(min(280px, 100%), 1fr)`
- [ ] `100dvh` used instead of `100vh` for full-height layoutsRelated Skills
open-u-dashboard
open understand dashboard for user
sync-template-skill
这是一个技能文件的模板,展示了技能的基本结构和内容组织方式。
talk-humanize
Be direct and informative. No filler, no fluff, but give enough to be useful.
search-web
使用 Evaluator-optimizer 模式进行系统性多轮网络搜索,采用结构化 Ask 流程在搜索前澄清研究目标。基于 YC Office Hours 的提问方法论,确保搜索方向清晰、结果可验证。当用户需要深入调查复杂主题、验证假设或全面收集信息时使用。
save-to-eagle
归档网络内容到 Eagle 素材库。支持:(1) Behance/Pixiv 图片归档,(2) 网页视频录制(页面动画、滚动录制)。使用方式:'归档 [URL]' 归档图片;'录制网页视频 [URL]' 录制页面动画;'滚动录制 [URL]' 自动滚动截图。支持评分如 '归档 [URL], 3/5'。
save-ob-chaos
将对话内容快速存档到 Obsidian Chaos 文件夹。触发词:"存档到 Obsidian"、"保存到 Chaos"、"ob 存档"、"记下这个"、"保存这段内容"、"存到 chaos"。
save-ob-chaos-mermaid
将 Mermaid 图表保存到 Obsidian Chaos 文件夹。触发词:"保存 mermaid 到 chaos"、"mermaid 存档"。
save-ob-chaos-excalidraw
绘制 Excalidraw 图表并存档到 Obsidian Chaos 文件夹。触发词:"画个图存到 Obsidian"、"excalidraw 存档"、"画个流程图保存"、"画图存到 chaos"、"创建图表并存档"、"画架构图到 ob"。
release-project
项目版本发布流程指导,帮助用户完成版本规划、Changelog 管理、版本号升级、Git 标签创建和 npm 首次发布准备。Use when: (1) 用户需要发布新版本 (2) 需要创建版本发布流程 (3) 需要管理版本号和 Changelog (4) 需要自动化版本发布 (5) 需要检查 release 分支同步 (6) 首次 npm 发布准备
recognize-codebase-branch-flow
识别并记忆项目 git 分支模型
rebase-commits
将零散的 commits 整合为清晰的逻辑提交,使 Git 历史更易读。 Use when: (1) 用户说 "rebase commits"、"整理提交历史"、"让历史更干净" (2) 用户想将多个相关 commits 合并为逻辑单元 (3) 完成一个功能后需要清理 commit 历史 (4) 提交历史混乱,需要重新组织
read-codebase
阅读棕地项目代码库,智能分析代码结构,递归补充其调用链上所有函数的注释。