frontend-tailwind-best-practices by sergiodxa/agent-skills
npx skills add https://github.com/sergiodxa/agent-skills --skill frontend-tailwind-best-practices前端应用的样式模式和规范。包含 10 条规则,涵盖布局工具、功能可见性、配色方案、响应式设计和 className 处理。
在以下情况时参考这些指南:
使用自定义堆叠工具类替代 flex 类。
// Bad
<div className="flex flex-col gap-4">
<div className="flex flex-row gap-4">
// Good
<div className="v-stack gap-4">
<div className="h-stack gap-4">
可用工具类:
v-stack - 垂直堆叠(flex 列)h-stack - 水平堆叠(flex 行)v-stack-reverse - 反向垂直堆叠h-stack-reverse - 反向水平堆叠广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
z-stack - 重叠堆叠(基于网格,子元素在彼此之上居中)center - 水平和垂直居中内容spacer - 填充可用空间的弹性间隔器circle - 宽高比为 1/1 的完美圆形在父元素上使用 gap-* 替代子元素的外边距。
// Bad
<div>
<Item className="mb-4" />
<Item className="mb-4" />
</div>
// Good
<div className="flex flex-col gap-4">
<Item />
<Item />
</div>
在断点处切换布局方向。
// Mobile: vertical, Desktop: horizontal
<div className="v-stack lg:h-stack gap-4">
<main className="grow">...</main>
<aside className="shrink-0 lg:w-80">...</aside>
</div>
// Mobile: horizontal, Desktop: vertical
<div className="h-stack md:v-stack">
使用基于类的配色方案和自定义的 dark 变体。
<button className="rounded-full bg-gray-900 px-4 py-2 text-white dark:bg-gray-100 dark:text-gray-900">
Toggle
</button>
在组件中始终使用 cn() 来合并 classNames。
import { cn } from "~/lib/cn";
function Button({ className, variant }: Props) {
return (
<button
className={cn(
"base-classes",
{
"variant-primary": variant === "primary",
"variant-secondary": variant === "secondary",
},
className, // external className always last
)}
/>
);
}
为 className 属性使用正确的类型。
import type { ClassName, ClassNameRecord } from "~/lib/cn";
// Single element
type Props = {
className?: ClassName;
};
// Multiple elements
type Props = {
className?: ClassNameRecord<"root" | "label" | "input">;
};
// Usage
<Input className={{ root: "w-full", label: "font-bold" }} />;
定义与工具类组合使用的、与元素无关的视觉模式。
<label className="ui-button" htmlFor="document-upload">
Choose file
</label>
使用 Tailwind 默认的响应式前缀。
// Standard breakpoints (min-width)
<div className="px-4 md:px-8 lg:px-12">
// Show/hide with standard breakpoints
<div className="hidden md:block">Desktop only</div>
<div className="md:hidden">Mobile only</div>
响应式缩放文本。
// Responsive font size
<h1 className="text-2xl md:text-3xl lg:text-4xl">
// Responsive line height with text
<p className="text-sm leading-5 md:text-base md:leading-6">
根据输入能力(指针/悬停)而非设备标签进行设计。
<button className="h-10 w-10 pointer-coarse:h-12 pointer-coarse:w-12">
<Icon />
</button>
| 不要 | 要 |
|---|---|
flex flex-col | v-stack |
flex flex-row | h-stack |
flex items-center justify-center | center |
bg-gray-100 | bg-neutral-100 |
bg-[#hex] | 使用设计令牌 |
className="..." 不使用 cn() | cn("...", className) |
内联 style 用于响应式 | Tailwind 前缀 |
| 文件 | 用途 |
|---|---|
tailwind.config.js | 配置、自定义工具类、颜色 |
app/styles/global.css | 配色方案 CSS 变量 |
app/styles/tailwind.css | 附加工具类 |
app/utils/cn.ts | className 合并工具 |
每周安装量
241
代码仓库
GitHub 星标数
80
首次出现
2026 年 1 月 28 日
安全审计
已安装于
opencode214
codex205
gemini-cli197
github-copilot192
cursor179
kimi-cli171
Styling patterns and conventions for frontend applications. Contains 10 rules covering layout utilities, affordances, color schemes, responsive design, and className handling.
Reference these guidelines when:
Use custom stack utilities instead of flex classes.
// Bad
<div className="flex flex-col gap-4">
<div className="flex flex-row gap-4">
// Good
<div className="v-stack gap-4">
<div className="h-stack gap-4">
Available utilities:
v-stack - Vertical stack (flex column)h-stack - Horizontal stack (flex row)v-stack-reverse - Reversed vertical stackh-stack-reverse - Reversed horizontal stackz-stack - Overlapping stack (grid-based, centers children on top of each other)center - Center content both horizontally and verticallyspacer - Flexible spacer that fills available spacecircle - Perfect circle with aspect-ratio 1/1Use gap-* on parents instead of child margins.
// Bad
<div>
<Item className="mb-4" />
<Item className="mb-4" />
</div>
// Good
<div className="flex flex-col gap-4">
<Item />
<Item />
</div>
Switch layout direction at breakpoints.
// Mobile: vertical, Desktop: horizontal
<div className="v-stack lg:h-stack gap-4">
<main className="grow">...</main>
<aside className="shrink-0 lg:w-80">...</aside>
</div>
// Mobile: horizontal, Desktop: vertical
<div className="h-stack md:v-stack">
Use class-based color schemes with a custom dark variant.
<button className="rounded-full bg-gray-900 px-4 py-2 text-white dark:bg-gray-100 dark:text-gray-900">
Toggle
</button>
Always use cn() to merge classNames in components.
import { cn } from "~/lib/cn";
function Button({ className, variant }: Props) {
return (
<button
className={cn(
"base-classes",
{
"variant-primary": variant === "primary",
"variant-secondary": variant === "secondary",
},
className, // external className always last
)}
/>
);
}
Use proper types for className props.
import type { ClassName, ClassNameRecord } from "~/lib/cn";
// Single element
type Props = {
className?: ClassName;
};
// Multiple elements
type Props = {
className?: ClassNameRecord<"root" | "label" | "input">;
};
// Usage
<Input className={{ root: "w-full", label: "font-bold" }} />;
Define element-agnostic visual patterns that compose with utilities.
<label className="ui-button" htmlFor="document-upload">
Choose file
</label>
Use responsive prefixes with Tailwind defaults.
// Standard breakpoints (min-width)
<div className="px-4 md:px-8 lg:px-12">
// Show/hide with standard breakpoints
<div className="hidden md:block">Desktop only</div>
<div className="md:hidden">Mobile only</div>
Scale text responsively.
// Responsive font size
<h1 className="text-2xl md:text-3xl lg:text-4xl">
// Responsive line height with text
<p className="text-sm leading-5 md:text-base md:leading-6">
Design for input capabilities (pointer/hover) instead of device labels.
<button className="h-10 w-10 pointer-coarse:h-12 pointer-coarse:w-12">
<Icon />
</button>
| Don't | Do |
|---|---|
flex flex-col | v-stack |
flex flex-row | h-stack |
flex items-center justify-center | center |
bg-gray-100 | bg-neutral-100 |
| File | Purpose |
|---|---|
tailwind.config.js | Config, custom utilities, colors |
app/styles/global.css | Color scheme CSS variables |
app/styles/tailwind.css | Additional utilities |
app/utils/cn.ts | className merge utility |
Weekly Installs
241
Repository
GitHub Stars
80
First Seen
Jan 28, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode214
codex205
gemini-cli197
github-copilot192
cursor179
kimi-cli171
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
106,200 周安装
Skill Creator 技能创建指南:构建高效 Codex 技能的最佳实践与原则
408 周安装
tscircuit:使用TypeScript和React设计电子电路的完整指南与工具
321 周安装
Supabase 最佳实践指南:Clerk 集成、RLS 安全与性能优化
306 周安装
Vue3 官方指南与API参考 - 从入门到精通,学习组件、响应式系统与最佳实践
347 周安装
TanStack Table 中文指南:React 无头表格库,实现排序过滤分页
418 周安装
免费无限网页搜索技能 - 无需API密钥,使用DuckDuckGo保护隐私
375 周安装
bg-[#hex] | Use design tokens |
className="..." without cn() | cn("...", className) |
Inline style for responsive | Tailwind prefixes |