tailwind
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTailwind CSS (v4+)
Tailwind CSS (v4+)
Overview
概述
Tailwind CSS v4 skill covering CSS-first configuration, design tokens, component patterns, shadcn/ui integration, dark mode, container queries, migration from v3, and custom utilities.
When to use: Configuring Tailwind themes, building utility-first components, implementing dark mode, using container queries, migrating from v3, integrating shadcn/ui, troubleshooting build errors.
When NOT to use: Tailwind v3 legacy projects that will not upgrade, projects using a different styling approach (CSS Modules, styled-components) without plans to adopt Tailwind.
本Tailwind CSS v4技能涵盖CSS优先配置、设计令牌、组件模式、shadcn/ui集成、暗黑模式、容器查询、从v3版本迁移以及自定义工具类等内容。
适用场景: 配置Tailwind主题、构建工具优先的组件、实现暗黑模式、使用容器查询、从v3版本迁移、集成shadcn/ui、排查构建错误。
不适用场景: 不打算升级的Tailwind v3遗留项目,以及未计划采用Tailwind、使用其他样式方案(如CSS Modules、styled-components)的项目。
Quick Reference
快速参考
| Pattern | API | Key Points |
|---|---|---|
| CSS-first config | | All config in CSS, no |
| Import entry | | Replaces |
| Custom utilities | | Replaces |
| Functional utilities | | Accept dynamic values via |
| Plugin loading | | Replaces |
| Container queries | | Built-in, no plugin needed |
| Named containers | | Scope queries to specific containers |
| Dark mode variant | | Class-based dark mode override |
| Theme inline | | Inlines values at build, single-theme only |
| Source detection | | Explicitly add scan paths |
| Reference import | | Use theme in Vue/Svelte scoped styles |
| Override defaults | | Reset a category before redefining |
| Dynamic values | | Use CSS variables in utility values |
| Text shadows | | Built-in text shadow utilities |
| Starting styles | | |
| Masks | | CSS mask utilities for image/gradient masking |
| Field sizing | | Auto-sizing textareas and inputs |
| Inset shadows | | Inner shadow and ring utilities |
| User validation | | Form validation after user interaction |
| Pointer queries | | Target input device precision |
| Inert | | Style inert elements |
| Logical spacing | | Block-direction padding/margin (v4.2) |
| Logical sizing | | Logical width/height utilities (v4.2) |
| Logical inset | | Logical positioning; replaces |
| Logical borders | | Block-direction border utilities (v4.2) |
| Font features | | OpenType |
| New color palettes | | Additional neutral palettes (v4.2) |
| Webpack integration | | Run Tailwind as a webpack plugin (v4.2) |
| Color space | OKLCH | Default in v4, sRGB fallbacks generated |
| 模式 | API | 核心要点 |
|---|---|---|
| CSS优先配置 | | 所有配置均在CSS中完成,无需 |
| 导入入口 | | 替代 |
| 自定义工具类 | | 替代 |
| 函数式工具类 | | 通过 |
| 插件加载 | | 替代配置文件中的 |
| 容器查询 | | 内置功能,无需额外插件 |
| 命名容器 | | 将查询范围限定到特定容器 |
| 暗黑模式变体 | | 基于类的暗黑模式覆盖方案 |
| 内联主题 | | 构建时内联值,仅适用于单主题场景 |
| 源文件检测 | | 显式添加扫描路径 |
| 引用导入 | | 在Vue/Svelte作用域样式中使用主题 |
| 覆盖默认值 | | 重新定义前重置分类值 |
| 动态值 | | 在工具类值中使用CSS变量 |
| 文本阴影 | | 内置文本阴影工具类 |
| 初始样式 | | 用于入场动画的 |
| 遮罩 | | 用于图片/渐变遮罩的CSS工具类 |
| 字段自适应 | | 文本域与输入框自动调整尺寸 |
| 内阴影 | | 内阴影与环形边框工具类 |
| 用户验证状态 | | 用户交互后的表单验证状态 |
| 指针精度查询 | | 针对输入设备精度设置样式 |
| 惰性元素样式 | | 为惰性元素设置样式 |
| 逻辑间距 | | 块级方向内边距/外边距(v4.2版本新增) |
| 逻辑尺寸 | | 逻辑宽度/高度工具类(v4.2版本新增) |
| 逻辑定位 | | 逻辑定位工具类;替代 |
| 逻辑边框 | | 块级方向边框工具类(v4.2版本新增) |
| 字体特性 | | OpenType |
| 新调色板 | | 新增中性调色板(v4.2版本新增) |
| Webpack集成 | | 将Tailwind作为webpack插件运行(v4.2版本新增) |
| 颜色空间 | OKLCH | v4版本默认颜色空间,自动生成sRGB降级方案 |
Common Mistakes
常见错误
| Mistake | Correct Pattern |
|---|---|
Using | Configure via |
| Reference directly: |
| Define at root level, outside any |
| Use |
| Use |
Raw colors like | Semantic tokens ( |
| Use |
| Use |
Missing | Map all CSS variables in |
Using | Use |
Using deprecated | Use |
| 错误做法 | 正确模式 |
|---|---|
在v4中使用 | 通过CSS中的 |
双重包裹 | 直接引用: |
在 | 在根级别定义,置于所有 |
对 | 对自定义工具类使用 |
为多主题切换使用 | 动态主题使用不带 |
随处使用 | 使用可自动适配的语义化令牌(如 |
使用 | 使用 |
在v4中使用 | 改用 |
集成shadcn/ui时缺少 | 在 |
在CSS中使用 | 使用原生CSS变量 |
使用已弃用的 | 使用 |
Delegation
任务分工
- Class pattern discovery and usage examples: Use agent
Explore - v3 to v4 migration across multiple files: Use agent
Task - Design token hierarchy and theming architecture: Use agent
Plan
If theskill is available, delegate complex animation patterns (spring physics, gestures, scroll-linked) to it.motion
- 类模式探索与使用示例:使用Agent
Explore - 多文件从v3到v4迁移:使用Agent
Task - 设计令牌层级与主题架构:使用Agent
Plan
若技能可用,可将复杂动画模式(如弹簧物理效果、手势、滚动关联动画)委托给该技能处理。motion
References
参考资料
- Configuration -- CSS-first config, @theme, @theme inline, @utility, @plugin, @source, @reference, @variant directives
- Design Tokens -- OKLCH token system, brand scales, semantic tokens, shadows, z-index, fluid typography
- Component Patterns -- Layouts, grids, container queries, 3D transforms, subgrid, CVA variants
- UI Patterns -- Buttons, forms, navigation, cards, typography with variants, states, accessibility
- Dark Mode -- Class-based dark mode, multi-theme systems, ThemeProvider, @custom-variant
- shadcn/ui Integration -- Four-step architecture, components.json, tw-animate-css, Vite setup
- Migration -- v3 to v4 migration steps, breaking changes, upgrade tool, common gotchas
- Troubleshooting -- Common errors, build fixes, CSS layer issues, PostCSS problems
- 配置 -- CSS优先配置、@theme、@theme inline、@utility、@plugin、@source、@reference、@variant 指令
- 设计令牌 -- OKLCH令牌系统、品牌色阶、语义化令牌、阴影、z-index、流式排版
- 组件模式 -- 布局、网格、容器查询、3D变换、子网格、CVA变体
- UI模式 -- 按钮、表单、导航、卡片、带变体的排版、状态、可访问性
- 暗黑模式 -- 基于类的暗黑模式、多主题系统、ThemeProvider、@custom-variant
- shadcn/ui集成 -- 四步架构、components.json、tw-animate-css、Vite配置
- 迁移指南 -- 从v3到v4的迁移步骤、破坏性变更、升级工具、常见陷阱
- 故障排查 -- 常见错误、构建修复、CSS层级问题、PostCSS问题