shadcn-layouts by jwynia/agent-skills
npx skills add https://github.com/jwynia/agent-skills --skill shadcn-layouts帮助生成首次渲染即正确的 shadcn/Tailwind 组件。大多数由智能体生成的 UI 失败的原因并非语法错误,而是由于缺乏对 CSS 布局工作原理的心智模型——即假设上的差距。
在以下情况使用此技能:
在以下情况不要使用此技能:
CSS 布局源于约束。高度从显式祖先元素向下传递。宽度从内容向上传递。智能体失败是因为它们在应用类时没有理解约束链。
h-full 意味着 height: 100%。100% 的什么?100% 的父元素的计算高度。
错误(链不完整):
<html> <!-- 无高度 -->
<body> <!-- 无高度 -->
<div class="h-full"> <!-- 100% 的 0 = 0 -->
正确(链完整):
<html class="h-full"> <!-- 视口的 100% -->
<body class="h-full"> <!-- html 的 100% -->
<div class="h-full"> <!-- body 的 100% = 生效 -->
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
规则: 从元素向上追溯到 <html>。每个祖先都需要显式高度,或者使用视口单位(h-screen)来打破链条。
Flex 子元素具有隐式的 min-height: auto,这阻止了其缩小到内容尺寸以下。
// 错误(不会滚动)
<div className="flex flex-col h-screen">
<main className="flex-1 overflow-y-auto"> {/* 无法缩小! */}
// 正确(正确滚动)
<div className="flex flex-col h-screen">
<main className="flex-1 overflow-y-auto min-h-0"> {/* 可以缩小 */}
规则: 需要滚动的 Flex 子元素需要 min-h-0。不应缩小的子元素需要 shrink-0。
Grid 定义在父元素上。子元素只是占据单元格。
// 错误
<div className="grid-cols-3"> {/* 缺少 'grid'! */}
// 正确
<div className="grid grid-cols-3"> {/* 'grid' 启用 grid-cols-* */}
规则: 必须在父元素上声明 flex 或 grid,方向/模板类才能生效。
滚动容器需要显式尺寸才能知道何时滚动。
// 错误(从不滚动)
<ScrollArea> {/* 无高度约束 */}
// 正确(受 flex 约束)
<div className="flex flex-col h-screen">
<ScrollArea className="flex-1 min-h-0">
症状: 元素折叠,h-full 不生效 修复: 向上追溯到 html,添加高度或使用 h-screen
症状: 滚动不生效,内容溢出 修复: 为需要滚动的 flex 子元素添加 min-h-0
症状: 项目垂直堆叠而不是分列 修复: 确保父元素上有 grid grid-cols-*
症状: 组件未样式化,颜色错误 修复: 检查 Tailwind 内容路径,globals.css 中的 CSS 变量
症状: "Module not found",功能损坏 修复: npx shadcn add [component],安装 peer 依赖
// layout.tsx
<html lang="en" className="h-full">
<body className="h-full">{children}</body>
</html>
// page.tsx
<div className="flex h-full">
<aside className="w-64 shrink-0 border-r overflow-y-auto">
<nav>...</nav>
</aside>
<main className="flex-1 min-w-0 overflow-y-auto">
{children}
</main>
</div>
<div className="flex flex-col h-screen">
<header className="h-16 shrink-0 border-b">...</header>
<div className="flex flex-1 min-h-0">
<aside className="w-64 shrink-0 border-r overflow-y-auto">...</aside>
<main className="flex-1 min-w-0 overflow-y-auto p-6">
{children}
</main>
</div>
</div>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
{items.map(item => (
<Card key={item.id}>
<CardHeader><CardTitle>{item.title}</CardTitle></CardHeader>
<CardContent>{item.content}</CardContent>
</Card>
))}
</div>
使用 h-full 而不验证祖先链。修复: 向上追溯到 html。使用 h-screen 来打破链条。
在 flex 子元素上添加 overflow-y-auto 而没有 min-h-0。修复: Flex 子元素需要 min-h-0 才能缩小。
猜测导入路径,如 shadcn/ui。修复: 检查 components.json 中的别名。通常是 @/components/ui/*。
扁平化复合组件(例如 Dialog 没有 DialogTrigger/DialogContent)。修复: 保持所需的嵌套结构。
@/components/ui/*)h-fullh-full 或 min-h-fullmin-h-0shrink-0每周安装次数
145
代码仓库
GitHub 星标
37
首次出现
2026年1月20日
安全审计
安装于
opencode120
codex118
gemini-cli114
cursor112
github-copilot108
claude-code100
Help generate shadcn/Tailwind components that render correctly the first time. Most agent-generated UI fails due to missing mental models about how CSS layout works—not syntax errors, but assumption gaps.
Use this skill when:
Do NOT use this skill when:
CSS layout flows from constraints. Height flows down from explicit ancestors. Width flows up from content. Agents fail because they apply classes without understanding the constraint chain.
h-full means height: 100%. 100% of what? 100% of the parent's computed height.
BROKEN (chain incomplete):
<html> <!-- no height -->
<body> <!-- no height -->
<div class="h-full"> <!-- 100% of nothing = 0 -->
WORKING (chain complete):
<html class="h-full"> <!-- 100% of viewport -->
<body class="h-full"> <!-- 100% of html -->
<div class="h-full"> <!-- 100% of body = works -->
Rule: Trace from element up to <html>. Every ancestor needs explicit height, OR use viewport units (h-screen) to break the chain.
Flex children have implicit min-height: auto, preventing shrinking below content size.
// BROKEN (won't scroll)
<div className="flex flex-col h-screen">
<main className="flex-1 overflow-y-auto"> {/* Can't shrink! */}
// WORKING (scrolls correctly)
<div className="flex flex-col h-screen">
<main className="flex-1 overflow-y-auto min-h-0"> {/* Can shrink */}
Rule: Flex children that scroll need min-h-0. Children that shouldn't shrink need shrink-0.
Grid is defined on the parent. Children just occupy cells.
// BROKEN
<div className="grid-cols-3"> {/* Missing 'grid'! */}
// WORKING
<div className="grid grid-cols-3"> {/* 'grid' enables grid-cols-* */}
Rule: flex or grid must be declared on parent before direction/template classes work.
Scroll containers need explicit dimensions to know when to scroll.
// BROKEN (never scrolls)
<ScrollArea> {/* No height constraint */}
// WORKING (flex-constrained)
<div className="flex flex-col h-screen">
<ScrollArea className="flex-1 min-h-0">
Symptoms: Elements collapse, h-full not working Fix: Trace to html, add heights or use h-screen
Symptoms: Scroll doesn't work, content overflows Fix: Add min-h-0 to flex children that scroll
Symptoms: Items stack vertically instead of columns Fix: Ensure grid grid-cols-* on parent
Symptoms: Unstyled components, colors wrong Fix: Check Tailwind content paths, CSS variables in globals.css
Symptoms: "Module not found", functionality broken Fix: npx shadcn add [component], install peer deps
// layout.tsx
<html lang="en" className="h-full">
<body className="h-full">{children}</body>
</html>
// page.tsx
<div className="flex h-full">
<aside className="w-64 shrink-0 border-r overflow-y-auto">
<nav>...</nav>
</aside>
<main className="flex-1 min-w-0 overflow-y-auto">
{children}
</main>
</div>
<div className="flex flex-col h-screen">
<header className="h-16 shrink-0 border-b">...</header>
<div className="flex flex-1 min-h-0">
<aside className="w-64 shrink-0 border-r overflow-y-auto">...</aside>
<main className="flex-1 min-w-0 overflow-y-auto p-6">
{children}
</main>
</div>
</div>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
{items.map(item => (
<Card key={item.id}>
<CardHeader><CardTitle>{item.title}</CardTitle></CardHeader>
<CardContent>{item.content}</CardContent>
</Card>
))}
</div>
Using h-full without verifying ancestor chain. Fix: Trace to html. Use h-screen to break chain.
Adding overflow-y-auto without min-h-0 on flex children. Fix: Flex children need min-h-0 to shrink.
Guessing import paths like shadcn/ui. Fix: Check components.json for alias. Usually @/components/ui/*.
Flattening compound components (Dialog without DialogTrigger/DialogContent). Fix: Maintain required nesting structure.
@/components/ui/*)h-fullh-full or min-h-fullmin-h-0shrink-0Weekly Installs
145
Repository
GitHub Stars
37
First Seen
Jan 20, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode120
codex118
gemini-cli114
cursor112
github-copilot108
claude-code100
json-render生成式UI框架:AI驱动、多平台JSON渲染,安全构建动态界面
529 周安装
dotnet-install:自动化 .NET SDK 和运行时安装指南 - 支持 Windows/macOS/Linux
85 周安装
UltraThink Orchestrator - 已弃用的AI工作流编排工具,推荐使用dev-orchestrator替代
85 周安装
数据库管理员技能:PostgreSQL/MySQL/MongoDB高可用架构、性能调优与灾难恢复
86 周安装
PDF编程技能:使用PDFKit、PDF.js、Puppeteer生成、解析、合并PDF文档
86 周安装
Spring Boot 3 工程师技能指南:微服务、云原生与响应式编程最佳实践
86 周安装
第一性原理思维教练:苏格拉底式提问,拆解难题,从零重建创新解决方案
86 周安装