跳到正文
Skillpedia
品牌48k · #5922

tailwind-patterns

它能做什么

这个工具可以帮你配置和使用 Tailwind CSS 的最新功能,比如直接在 CSS 中定义样式、为单个组件使用更小的屏幕断点,以及创建现代化的布局。

适用场景

  • ✓配置 Tailwind CSS 4 版本时。
  • ✓以有条理的方式定义颜色、间距和字体时。
  • ✓创建需要适应不同屏幕尺寸或页面特定部分的设计时。

技能链接

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/tailwind-patterns/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/tailwind-patterns/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“我想用新的 token 系统设置主色和辅色,应该怎么做?”

每周 5 个新技能,1 分钟读完。

工作原理

你可以使用 @theme 指令直接在 CSS 文件中定义样式。这样就能更高效地组织颜色、字体和间距,还能使用“容器查询”(container queries)等新功能,让组件根据自身情况进行适配。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Tailwind CSS Patterns (v4 - 2025)

Modern utility-first CSS with CSS-native configuration.

When to Use

Use this skill when configuring Tailwind v4, using CSS-first theme and design tokens, or implementing container queries and modern Tailwind patterns.


1. Tailwind v4 Architecture

What Changed from v3

v3 (Legacy) v4 (Current)
tailwind.config.js CSS-based @theme directive
PostCSS plugin Oxide engine (10x faster)
JIT mode Native, always-on
Plugin system CSS-native features
@apply directive Still works, discouraged

v4 Core Concepts

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 --* vars

2. CSS-Based Configuration

Theme Definition

@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;
}

When to Extend vs Override

Action Use When
Extend Adding new values alongside defaults
Override Replacing default scale entirely
Semantic tokens Project-specific naming (primary, surface)

3. Container Queries (v4 Native)

Breakpoint vs Container

Type Responds To
Breakpoint (md:) Viewport width
Container (@container) Parent element width

Container Query Usage

Pattern Classes
Define container @container on parent
Container breakpoint @sm:, @md:, @lg: on children
Named containers @container/card for specificity

When to Use

Scenario Use
Page-level layouts Viewport breakpoints
Component-level responsive Container queries
Reusable components Container queries (context-independent)

4. Responsive Design

Breakpoint System

Prefix Min Width Target
(none) 0px Mobile-first base
sm: 640px Large phone / small tablet
md: 768px Tablet
lg: 1024px Laptop
xl: 1280px Desktop
2xl: 1536px Large desktop

Mobile-First Principle

  1. Write mobile styles first (no prefix)
  2. Add larger screen overrides with prefixes
  3. Example: w-full md:w-1/2 lg:w-1/3

5. Dark Mode

Configuration Strategies

Method Behavior Use When
class .dark class toggles Manual theme switcher
media Follows system preference No user control
selector Custom selector (v4) Complex theming

Dark Mode Pattern

Element Light Dark
Background bg-white dark:bg-zinc-900
Text text-zinc-900 dark:text-zinc-100
Borders border-zinc-200 dark:border-zinc-700

6. Modern Layout Patterns

Flexbox Patterns

Pattern Classes
Center (both axes) flex items-center justify-center
Vertical stack flex flex-col gap-4
Horizontal row flex gap-4
Space between flex justify-between items-center
Wrap grid flex flex-wrap gap-4

Grid Patterns

Pattern Classes
Auto-fit responsive grid grid-cols-[repeat(auto-fit,minmax(250px,1fr))]
Asymmetric (Bento) grid grid-cols-3 grid-rows-2 with spans
Sidebar layout grid grid-cols-[auto_1fr]

Note: Prefer asymmetric/Bento layouts over symmetric 3-column grids.


7. Modern Color System

OKLCH vs RGB/HSL

Format Advantage
OKLCH Perceptually uniform, better for design
HSL Intuitive hue/saturation
RGB Legacy compatibility

Color Token Architecture

Layer Example Purpose
Primitive --blue-500 Raw color values
Semantic --color-primary Purpose-based naming
Component --button-bg Component-specific

8. Typography System

…

常见问题

“breakpoint”和“container query”有什么区别?

breakpoint 指的是整个屏幕的尺寸,而 container query 指的是父元素的尺寸。这样组件就可以独立于页面尺寸进行适配。

怎样让网站在操作系统开启深色模式时自动切换为深色?

你可以在 Tailwind 配置中使用 media 策略,让深色模式跟随系统设置。

什么是“设计令牌”(design tokens)?

它们是代表设计数值的变量,比如颜色和间距。它们有助于保持视觉一致性,并让项目中的样式更新更加方便。

详情

作者的原始描述

Tailwind CSS v4 principles. CSS-first configuration, container queries, modern patterns, design token architecture.

repo: sickn33/agentic-awesome-skills

热度

GitHub 星标
48k
排名
#5922
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能