Loading...
Loading...
Compare original and translation side by side
// vite.config.ts
import tailwindcss from '@tailwindcss/vite';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [tailwindcss()],
});/* src/index.css */
@import 'tailwindcss';@theme inline {
--color-primary: oklch(60% 0.24 262);
--color-surface: oklch(98% 0.002 247);
}// vite.config.ts
import tailwindcss from '@tailwindcss/vite';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [tailwindcss()],
});/* src/index.css */
@import 'tailwindcss';@theme inline {
--color-primary: oklch(60% 0.24 262);
--color-surface: oklch(98% 0.002 247);
}| Feature | v3 | v4 |
|---|---|---|
| Configuration | tailwind.config.js | @theme in CSS |
| Build Tool | PostCSS plugin | @tailwindcss/vite |
| Colors | rgb() / hsl() | oklch() (default) |
| Theme Extension | extend: {} in JS | CSS variables |
| Dark Mode | darkMode config option | CSS variants |
| 特性 | v3 | v4 |
|---|---|---|
| 配置方式 | tailwind.config.js | CSS中的@theme指令 |
| 构建工具 | PostCSS插件 | @tailwindcss/vite |
| 颜色格式 | rgb() / hsl() | 默认使用oklch() |
| 主题扩展 | JS中的extend: {} | CSS变量 |
| 暗黑模式 | darkMode配置项 | CSS变体 |
@theme {
--color-brand: oklch(60% 0.24 262);
}
/* Generates: :root { --color-brand: oklch(...); } */
/* Usage: text-brand → color: var(--color-brand) */@theme default@theme {
--color-brand: oklch(60% 0.24 262);
}
/* 生成结果: :root { --color-brand: oklch(...); } */
/* 使用方式: text-brand → color: var(--color-brand) */@theme default@theme inline {
--color-brand: oklch(60% 0.24 262);
}
/* Usage: text-brand → color: oklch(60% 0.24 262) */@theme inline {
--color-brand: oklch(60% 0.24 262);
}
/* 使用方式: text-brand → color: oklch(60% 0.24 262) */@theme reference {
--color-internal: oklch(50% 0.1 180);
}
/* No :root variable, but utilities use fallback */
/* Usage: bg-internal → background-color: var(--color-internal, oklch(50% 0.1 180)) */@theme reference {
--color-internal: oklch(50% 0.1 180);
}
/* 不会生成:root变量,但工具类会使用回退值 */
/* 使用方式: bg-internal → background-color: var(--color-internal, oklch(50% 0.1 180)) */oklch(L% C H)--color-sky-500: oklch(68.5% 0.169 237.323); /* Bright blue */
--color-red-600: oklch(57.7% 0.245 27.325); /* Vibrant red */
--color-zinc-900: oklch(21% 0.006 285.885); /* Near-black gray */oklch(L% C H)--color-sky-500: oklch(68.5% 0.169 237.323); /* 亮蓝色 */
--color-red-600: oklch(57.7% 0.245 27.325); /* 鲜艳红色 */
--color-zinc-900: oklch(21% 0.006 285.885); /* 近黑灰色 */@theme {
/* Colors: --color-{name}-{shade} */
--color-primary-500: oklch(60% 0.24 262);
/* Spacing: --spacing multiplier */
--spacing: 0.25rem; /* Base unit for spacing scale */
/* Fonts: --font-{family} */
--font-display: 'Inter Variable', system-ui, sans-serif;
/* Breakpoints: --breakpoint-{size} */
--breakpoint-lg: 64rem;
/* Custom animations: --animate-{name} */
--animate-fade-in: fade-in 0.3s ease-out;
}@theme {
/* 颜色: --color-{名称}-{色调} */
--color-primary-500: oklch(60% 0.24 262);
/* 间距: --spacing 乘数 */
--spacing: 0.25rem; /* 间距刻度的基础单位 */
/* 字体: --font-{字体族} */
--font-display: 'Inter Variable', system-ui, sans-serif;
/* 断点: --breakpoint-{尺寸} */
--breakpoint-lg: 64rem;
/* 自定义动画: --animate-{名称} */
--animate-fade-in: fade-in 0.3s ease-out;
}tailwind.config.jspostcss.config.js@types/node{
"devDependencies": {
"@tailwindcss/vite": "^4.0.0",
"@types/node": "^22.0.0",
"tailwindcss": "^4.0.0",
"vite": "^6.0.0"
}
}tailwind.config.jspostcss.config.js@types/node{
"devDependencies": {
"@tailwindcss/vite": "^4.0.0",
"@types/node": "^22.0.0",
"tailwindcss": "^4.0.0",
"vite": "^6.0.0"
}
}@theme inline@theme@theme inline@theme@theme reference@theme reference@theme {
/* Design tokens (OKLCH colors) */
--color-blue-600: oklch(54.6% 0.245 262.881);
--color-slate-800: oklch(27.9% 0.041 260.031);
/* Semantic mappings */
--color-primary: var(--color-blue-600);
--color-surface: var(--color-slate-800);
}
/* Usage: bg-primary, bg-surface */@theme {
/* 设计令牌(OKLCH颜色) */
--color-blue-600: oklch(54.6% 0.245 262.881);
--color-slate-800: oklch(27.9% 0.041 260.031);
/* 语义化映射 */
--color-primary: var(--color-blue-600);
--color-surface: var(--color-slate-800);
}
/* 使用方式: bg-primary, bg-surface */@theme {
--font-display: 'Inter Variable', system-ui, sans-serif;
--font-mono: 'JetBrains Mono', ui-monospace, monospace;
--font-display--font-variation-settings: 'wght' 400;
--font-display--font-feature-settings: 'cv02', 'cv03', 'cv04';
}
/* Usage: font-display, font-mono */@theme {
--font-display: 'Inter Variable', system-ui, sans-serif;
--font-mono: 'JetBrains Mono', ui-monospace, monospace;
--font-display--font-variation-settings: 'wght' 400;
--font-display--font-feature-settings: 'cv02', 'cv03', 'cv04';
}
/* 使用方式: font-display, font-mono */@theme inline {
--animate-beacon: beacon 2s ease-in-out infinite;
@keyframes beacon {
0%, 100% {
opacity: 1;
transform: scale(1);
}
50% {
opacity: 0.5;
transform: scale(1.05);
}
}
}
/* Usage: animate-beacon */@theme inline {
--animate-beacon: beacon 2s ease-in-out infinite;
@keyframes beacon {
0%, 100% {
opacity: 1;
transform: scale(1);
}
50% {
opacity: 0.5;
transform: scale(1.05);
}
}
}
/* 使用方式: animate-beacon */