Communitygithub.com

Tailwind CSS v4 模式 (2025)

CSS 優先的組態方式、容器查詢、現代化模式、設計 Token 架構。

Tailwind CSS v4 模式 (2025) 是什麼?

這份技能指南專注於 Tailwind CSS v4(2025 年版本)的現代化實務,特別強調 CSS 優先的組態方式。與 v3 依賴 JavaScript 組態檔不同,v4 使用 `@theme` 指令直接在 CSS 中定義設計 Token,並透過 Oxide 引擎(Rust 編譯器)達到 10 倍的建置速度。技能說明如何善用容器查詢實現元件層級的響應式設計,並介紹了 OKLCH 色彩空間、語意化 Token 架構、以及行動裝置優先的斷點系統。此外,還涵蓋了 Flexbox 與 Grid 的現代佈局模式、暗色模式策略、動畫與轉場的內建類別,以及元件提取與效能最佳化原則。這份指南支援 Claude Code、Cursor、Codex 等 AI 代理工具,協助開發者快速掌握 Tailwind v4 的核心變革與最佳實務。

相容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/marnixGeerkens/rocketlauncher-claude-code/tree/HEAD/components/skills/creative-design/tailwind-patterns

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Tailwind CSS 模式 (v4 - 2025)

以 CSS 原生組態為核心的現代工具優先 CSS。


1. Tailwind v4 架構

與 v3 的差異

v3 (舊版)v4 (現行版本)
tailwind.config.js基於 CSS 的 @theme 指令
PostCSS 外掛Oxide 引擎 (速度快 10 倍)
JIT 模式原生、永遠開啟
外掛系統CSS 原生功能
@apply 指令仍可使用,但不建議

v4 核心概念

概念說明
CSS 優先在 CSS 中進行組態,而非 JavaScript
Oxide 引擎基於 Rust 的編譯器,速度更快
原生巢狀CSS 巢狀語法,無需 PostCSS
CSS 變數所有 Token 均以 --* 變數形式公開

2. 基於 CSS 的組態

主題定義

@theme {
  /* 色彩 - 使用語意化名稱 */
  --color-primary: oklch(0.7 0.15 250);
  --color-surface: oklch(0.98 0 0);
  --color-surface-dark: oklch(0.15 0 0);
  
  /* 間距比例 */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 2rem;
  
  /* 字型 */
  --font-sans: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

何時擴充 vs 覆寫

動作使用時機
擴充在預設值之外新增新值
覆寫完全取代預設比例
語意 Token專案專屬命名 (primary, surface)

3. 容器查詢 (v4 原生)

斷點 vs 容器

類型回應對象
斷點 (md:)視窗寬度
容器 (@container)父元素寬度

容器查詢用法

模式類別
定義容器在父元素上使用 @container
容器斷點在子元素上使用 @sm:、@md:、@lg:
具名容器@container/card 以提高明確性

使用時機

情境使用方式
頁面層級佈局視窗斷點
元件層級響應式容器查詢
可重複使用元件容器查詢 (與上下文無關)

4. 響應式設計

斷點系統

前綴最小寬度目標裝置
(無)0px行動裝置優先基礎
sm:640px大手機 / 小平板
md:768px平板
lg:1024px筆電
xl:1280px桌上型電腦
2xl:1536px大型桌上型電腦

行動裝置優先原則

  1. 先撰寫行動裝置樣式 (不加前綴)
  2. 使用前綴為較大螢幕加入覆寫樣式
  3. 範例:w-full md:w-1/2 lg:w-1/3

5. 暗色模式

組態策略

方法行為使用時機
class透過 .dark 類別切換手動主題切換器
media跟隨系統偏好無使用者控制
selector自訂選擇器 (v4)複雜主題設定

暗色模式模式

元素亮色暗色
背景bg-whitedark:bg-zinc-900
文字text-zinc-900dark:text-zinc-100
邊框border-zinc-200dark:border-zinc-700

6. 現代佈局模式

Flexbox 模式

模式類別
居中 (雙軸)flex items-center justify-center
垂直堆疊flex flex-col gap-4
水平排列flex gap-4
兩端對齊flex justify-between items-center
換行網格flex flex-wrap gap-4

Grid 模式

模式類別
自動適應響應式grid grid-cols-[repeat(auto-fit,minmax(250px,1fr))]
不對稱 (Bento)grid grid-cols-3 grid-rows-2 搭配跨欄/跨列
側邊欄佈局grid grid-cols-[auto_1fr]

注意: 建議優先使用不對稱 / Bento 佈局,而非對稱的三欄網格。


7. 現代色彩系統

OKLCH vs RGB / HSL

格式優點
OKLCH知覺均勻,更適合設計
HSL色相/飽和度直觀
RGB舊版相容性

色彩 Token 架構

層級範例目的
原始--blue-500原始色彩數值
語意--color-primary基於用途的命名
元件--button-bg元件專屬

8. 字型系統

字型堆疊模式

類型建議
Sans'Inter', 'SF Pro', system-ui, sans-serif
Mono'JetBrains Mono', 'Fira Code', monospace
Display'Outfit', 'Poppins', sans-serif

字級比例

類別大小用途
text-xs0.75rem標籤、說明文字
text-sm0.875rem次要文字
text-base1rem內文
text-lg1.125rem引導文字
text-xl+1.25rem+標題

9. 動畫與轉場

內建動畫

類別效果
animate-spin持續旋轉
animate-ping注意力脈衝
animate-pulse微妙的透明度脈衝
animate-bounce彈跳效果

轉場模式

模式類別
所有屬性transition-all duration-200
特定屬性transition-colors duration-150
加上緩動ease-out 或 ease-in-out
懸停效果hover:scale-105 transition-transform

10. 元件提取

提取時機

訊號動作
相同類別組合出現 3 次以上提取為元件
複雜的狀態變體提取為元件
設計系統元素提取並撰寫文件

提取方法

方法使用時機
React / Vue 元件動態、需要 JavaScript
CSS 中的 @apply靜態、不需要 JavaScript
設計 Token可重複使用的數值

11. 反模式

不要這樣做應該這樣做
到處使用任意數值採用設計系統比例
!important正確解決明確性問題
內聯 style=使用工具類別
重複長串類別列表提取為元件
混合 v3 組態與 v4完全遷移至 CSS 優先
大量使用 @apply優先使用元件

12. 效能原則

原則實作方式
清除未使用樣式v4 自動執行
避免動態化不使用模板字串類別
使用 Oxidev4 預設,速度快 10 倍
快取建置CI/CD 快取

記住: Tailwind v4 是 CSS 優先。擁抱 CSS 變數、容器查詢與原生功能。組態檔現在是選用項目。

Individual skills in this repo

This repo contains 13 individual skills — each has its own dedicated page.

marnixGeerkens/rocketlauncher-claude-code

When the user wants to optimize, improve, or increase conversions on any marketing page — including homepage, landing pages, pricing pages, feature pages, or blog posts. Also use when the user says "CRO," "conversion rate optimization," "this page isn't converting," "improve conversions," or "why isn't this page working." For signup/registration flows, see signup-flow-cro. For post-signup activation, see onboarding-cro. For forms outside of signup, see form-cro. For popups/modals, see popup-cro.

marnixGeerkens/rocketlauncher-claude-code

Balance visual design with ATS compatibility for creative roles. Use when the user is in design, art, writing, marketing creative, or any visual/creative field and needs a resume that looks distinctive but still parses.

marnixGeerkens/rocketlauncher-claude-code

Transform resume bullets into detailed portfolio case studies with context, action, and outcome. Use when the user mentions portfolio, case study, project write-up, or expanding a resume bullet into a longer narrative.

marnixGeerkens/rocketlauncher-claude-code

Expert in building portfolios that actually land jobs and clients - not just showing work, but creating memorable experiences. Covers developer portfolios, designer portfolios, creative portfolios, and portfolios that convert visitors into opportunities. Use when: portfolio, personal website, showcase work, developer portfolio, designer portfolio.

marnixGeerkens/rocketlauncher-claude-code

Frontend development patterns for React, Next.js, state management, performance optimization, and UI best practices.

marnixGeerkens/rocketlauncher-claude-code

Frontend development guidelines for React/TypeScript applications. Modern patterns including Suspense, lazy loading, useSuspenseQuery, file organization with features directory, MUI v7 styling, TanStack Router, performance optimization, and TypeScript best practices. Use when creating components, pages, features, fetching data, styling, routing, or working with frontend code.

marnixGeerkens/rocketlauncher-claude-code

Next.js App Router principles. Server Components, data fetching, routing patterns.

marnixGeerkens/rocketlauncher-claude-code

Expert integration of Supabase Auth with Next.js App Router Use when: supabase auth next, authentication next.js, login supabase, auth middleware, protected route.

marnixGeerkens/rocketlauncher-claude-code

Comprehensive frontend development skill for building modern, performant web applications using ReactJS, NextJS, TypeScript, Tailwind CSS. Includes component scaffolding, performance optimization, bundle analysis, and UI best practices. Use when developing frontend features, optimizing performance, implementing UI/UX designs, managing state, or reviewing frontend code.

marnixGeerkens/rocketlauncher-claude-code

Create API handoff documentation for frontend developers. Use when backend work is complete and needs to be documented for frontend integration, or user says 'create handoff', 'document API', 'frontend handoff', or 'API documentation'.

marnixGeerkens/rocketlauncher-claude-code

Document frontend data needs for backend developers. Use when frontend needs to communicate API requirements to backend, or user says 'backend requirements', 'what data do I need', 'API requirements', or is describing data needs for a UI.

marnixGeerkens/rocketlauncher-claude-code

Comprehensive Python library for astronomy and astrophysics. This skill should be used when working with astronomical data including celestial coordinates, physical units, FITS files, cosmological calculations, time systems, tables, world coordinate systems (WCS), and astronomical data analysis. Use when tasks involve coordinate transformations, unit conversions, FITS file manipulation, cosmological distance calculations, time scale conversions, or astronomical data processing.

marnixGeerkens/rocketlauncher-claude-code

Comprehensive patterns for Next.js 14+ App Router architecture, Server Components, and modern full-stack React development.

相關技能