Loading...
Loading...
Compare original and translation side by side
Modern utility-first CSS with CSS-native configuration.
基于CSS原生配置的现代实用优先CSS框架。
| v3 (Legacy) | v4 (Current) |
|---|---|
| CSS-based |
| PostCSS plugin | Oxide engine (10x faster) |
| JIT mode | Native, always-on |
| Plugin system | CSS-native features |
| Still works, discouraged |
| v3(旧版) | v4(当前版) |
|---|---|
| 基于CSS的 |
| PostCSS 插件 | Oxide 引擎(速度提升10倍) |
| JIT 模式 | 原生内置、始终启用 |
| 插件系统 | CSS原生特性 |
| 仍可使用,但不推荐 |
| Concept | Description |
|---|---|
| CSS-first | Configuration in CSS, not JavaScript |
| Oxide Engine | Rust-based compiler, much faster |
| Native Nesting | CSS nesting without PostCSS |
| CSS Variables | All tokens exposed as |
| 概念 | 描述 |
|---|---|
| CSS优先 | 配置在CSS中完成,而非JavaScript |
| Oxide 引擎 | 基于Rust的编译器,速度大幅提升 |
| 原生嵌套 | 无需PostCSS即可实现CSS嵌套 |
| CSS Variables | 所有令牌均以 |
@theme {
/* Colors - use semantic names */
--color-primary: oklch(0.7 0.15 250);
--color-surface: oklch(0.98 0 0);
--color-surface-dark: oklch(0.15 0 0);
/* Spacing scale */
--spacing-xs: 0.25rem;
--spacing-sm: 0.5rem;
--spacing-md: 1rem;
--spacing-lg: 2rem;
/* Typography */
--font-sans: 'Inter', system-ui, sans-serif;
--font-mono: 'JetBrains Mono', monospace;
}@theme {
/* Colors - use semantic names */
--color-primary: oklch(0.7 0.15 250);
--color-surface: oklch(0.98 0 0);
--color-surface-dark: oklch(0.15 0 0);
/* Spacing scale */
--spacing-xs: 0.25rem;
--spacing-sm: 0.5rem;
--spacing-md: 1rem;
--spacing-lg: 2rem;
/* Typography */
--font-sans: 'Inter', system-ui, sans-serif;
--font-mono: 'JetBrains Mono', monospace;
}| Action | Use When |
|---|---|
| Extend | Adding new values alongside defaults |
| Override | Replacing default scale entirely |
| Semantic tokens | Project-specific naming (primary, surface) |
| 操作 | 适用场景 |
|---|---|
| 扩展 | 在默认值基础上添加新值 |
| 覆盖 | 完全替换默认的比例体系 |
| 语义令牌 | 项目专属命名(如primary、surface) |
| Type | Responds To |
|---|---|
Breakpoint ( | Viewport width |
Container ( | Parent element width |
| 类型 | 响应对象 |
|---|---|
断点( | 视口宽度 |
容器( | 父元素宽度 |
| Pattern | Classes |
|---|---|
| Define container | |
| Container breakpoint | |
| Named containers | |
| 模式 | 类名 |
|---|---|
| 定义容器 | 在父元素上使用 |
| 容器断点 | 在子元素上使用 |
| 命名容器 | 使用 |
| Scenario | Use |
|---|---|
| Page-level layouts | Viewport breakpoints |
| Component-level responsive | Container queries |
| Reusable components | Container queries (context-independent) |
| 场景 | 选择方案 |
|---|---|
| 页面级布局 | 视口断点 |
| 组件级响应式 | 容器查询 |
| 可复用组件 | 容器查询(与上下文无关) |
| Prefix | Min Width | Target |
|---|---|---|
| (none) | 0px | Mobile-first base |
| 640px | Large phone / small tablet |
| 768px | Tablet |
| 1024px | Laptop |
| 1280px | Desktop |
| 1536px | Large desktop |
| 前缀 | 最小宽度 | 目标设备 |
|---|---|---|
| (无) | 0px | 移动端优先基础样式 |
| 640px | 大屏手机/小平板 |
| 768px | 平板 |
| 1024px | 笔记本电脑 |
| 1280px | 桌面端 |
| 1536px | 大屏桌面端 |
w-full md:w-1/2 lg:w-1/3w-full md:w-1/2 lg:w-1/3| Method | Behavior | Use When |
|---|---|---|
| | Manual theme switcher |
| Follows system preference | No user control |
| Custom selector (v4) | Complex theming |
| 方法 | 行为 | 适用场景 |
|---|---|---|
| 通过 | 手动主题切换器 |
| 跟随系统偏好设置 | 无需用户控制 |
| 自定义选择器(v4新增) | 复杂主题配置 |
| Element | Light | Dark |
|---|---|---|
| Background | | |
| Text | | |
| Borders | | |
| 元素 | 亮色模式 | 暗色模式 |
|---|---|---|
| 背景 | | |
| 文本 | | |
| 边框 | | |
| Pattern | Classes |
|---|---|
| Center (both axes) | |
| Vertical stack | |
| Horizontal row | |
| Space between | |
| Wrap grid | |
| 模式 | 类名 |
|---|---|
| 居中对齐(双轴) | |
| 垂直堆叠 | |
| 水平排列 | |
| 两端对齐 | |
| 自动换行网格 | |
| Pattern | Classes |
|---|---|
| Auto-fit responsive | |
| Asymmetric (Bento) | |
| Sidebar layout | |
Note: Prefer asymmetric/Bento layouts over symmetric 3-column grids.
| 模式 | 类名 |
|---|---|
| 自适应响应式 | |
| 非对称布局(Bento) | |
| 侧边栏布局 | |
注意: 优先使用非对称/Bento布局,而非对称的3列网格。
| Format | Advantage |
|---|---|
| OKLCH | Perceptually uniform, better for design |
| HSL | Intuitive hue/saturation |
| RGB | Legacy compatibility |
| 格式 | 优势 |
|---|---|
| OKLCH | 感知均匀,更适合设计 |
| HSL | 色相/饱和度更直观 |
| RGB | 兼容旧系统 |
| Layer | Example | Purpose |
|---|---|---|
| Primitive | | Raw color values |
| Semantic | | Purpose-based naming |
| Component | | Component-specific |
| 层级 | 示例 | 用途 |
|---|---|---|
| 基础层 | | 原始色彩值 |
| 语义层 | | 基于用途的命名 |
| 组件层 | | 组件专属令牌 |
| Type | Recommended |
|---|---|
| Sans | |
| Mono | |
| Display | |
| 类型 | 推荐方案 |
|---|---|
| Sans | |
| Mono | |
| Display | |
| Class | Size | Use |
|---|---|---|
| 0.75rem | Labels, captions |
| 0.875rem | Secondary text |
| 1rem | Body text |
| 1.125rem | Lead text |
| 1.25rem+ | Headings |
| 类名 | 大小 | 用途 |
|---|---|---|
| 0.75rem | 标签、说明文字 |
| 0.875rem | 次要文本 |
| 1rem | 正文文本 |
| 1.125rem | 引导文本 |
| 1.25rem+ | 标题 |
| Class | Effect |
|---|---|
| Continuous rotation |
| Attention pulse |
| Subtle opacity pulse |
| Bouncing effect |
| 类名 | 效果 |
|---|---|
| 持续旋转 |
| 脉冲提醒 |
| 微妙的透明度脉冲 |
| 弹跳效果 |
| Pattern | Classes |
|---|---|
| All properties | |
| Specific | |
| With easing | |
| Hover effect | |
| 模式 | 类名 |
|---|---|
| 所有属性过渡 | |
| 指定属性过渡 | |
| 缓动效果 | |
| 悬停效果 | |
| Signal | Action |
|---|---|
| Same class combo 3+ times | Extract component |
| Complex state variants | Extract component |
| Design system element | Extract + document |
| 信号 | 操作 |
|---|---|
| 相同类组合出现3次以上 | 提取为组件 |
| 包含复杂状态变体 | 提取为组件 |
| 属于设计系统元素 | 提取并文档化 |
| Method | Use When |
|---|---|
| React/Vue component | Dynamic, JS needed |
| @apply in CSS | Static, no JS needed |
| Design tokens | Reusable values |
| 方法 | 适用场景 |
|---|---|
| React/Vue 组件 | 需要动态逻辑或JavaScript支持 |
CSS 中使用 | 静态样式,无需JavaScript |
| 设计令牌 | 可复用的样式值 |
| Don't | Do |
|---|---|
| Arbitrary values everywhere | Use design system scale |
| Fix specificity properly |
Inline | Use utilities |
| Duplicate long class lists | Extract component |
| Mix v3 config with v4 | Migrate fully to CSS-first |
Use | Prefer components |
| 不推荐做法 | 推荐做法 |
|---|---|
| 大量使用任意值 | 使用设计系统的比例体系 |
使用 | 正确修复特异性问题 |
使用内联 | 使用实用类 |
| 重复冗长的类列表 | 提取为组件 |
| 混合使用v3与v4配置 | 完全迁移到CSS优先的配置方式 |
大量使用 | 优先使用组件 |
| Principle | Implementation |
|---|---|
| Purge unused | Automatic in v4 |
| Avoid dynamism | No template string classes |
| Use Oxide | Default in v4, 10x faster |
| Cache builds | CI/CD caching |
Remember: Tailwind v4 is CSS-first. Embrace CSS variables, container queries, and native features. The config file is now optional.
| 原则 | 实现方式 |
|---|---|
| 清除未使用样式 | v4 自动完成 |
| 避免动态类名 | 不使用模板字符串生成类名 |
| 使用Oxide引擎 | v4 默认启用,速度提升10倍 |
| 缓存构建结果 | 在CI/CD中配置缓存 |
记住: Tailwind v4 是CSS优先的框架。拥抱CSS变量、容器查询和原生特性。配置文件现在是可选的。