界面已本地化;技能介绍与说明文档按所选语言由 AI 自动翻译,代码、命令、路径和专业术语保留原文,以原作者文档为准。
探索技能
设计与创意 · SKILL.md

tailwind-patterns

tailwind-patterns

【设计与创意】Tailwind CSS v4 principles for Angular 21.x — CSS-first @theme configuration, container queries, OKLCH color system, Bento layout patterns, dark mode strategies, and v3→v4 migration reference. Load alongside angular-spa for full Tailwind v4 coverage.

独立 GitHub 快照 · 自动分类 · 以原作者文档为准

技能说明

GitHub

name: tailwind-patterns description: "Tailwind CSS v4 principles for Angular 21.x — CSS-first @theme configuration, container queries, OKLCH color system, Bento layout patterns, dark mode strategies, and v3→v4 migration reference. Load alongside angular-spa for full Tailwind v4 coverage." risk: low source: community (adapted for Angular 21.x) date_added: "2026-02-27" updated: "2026-03-15" last-reviewed: "2026-03-15" allowed-tools:

  • Read
  • Grep
  • Glob
  • Edit
  • Write

Triggers

Load this skill when: configuring Tailwind v4, writing Angular templates with utility classes, migrating from Tailwind v3, implementing dark mode with daisyUI, or designing container-query-based layouts.


Iron Law

NO TAILWIND STYLING WITHOUT CHECKING THE PROJECT'S @theme CONFIGURATION FIRST — read the global CSS theme file before applying utility classes

Load the project's CSS @theme configuration and verify daisyUI semantic tokens before writing any template classes.

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, implementing container queries, or applying modern Tailwind patterns in Angular 21.x templates.


1. Tailwind v4 Architecture

What Changed from v3

v3 (Legacy)v4 (Current)
tailwind.config.jsCSS-based @theme directive
PostCSS pluginOxide engine (10x faster)
JIT modeNative, always-on
Plugin systemCSS-native features
@apply directiveStill works, discouraged

v4 Core Concepts

ConceptDescription
CSS-firstConfiguration in CSS, not JavaScript
Oxide EngineRust-based compiler, much faster
Native NestingCSS nesting without PostCSS
CSS VariablesAll 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

ActionUse When
ExtendAdding new values alongside defaults
OverrideReplacing default scale entirely
Semantic tokensProject-specific naming (primary, surface)

3. Container Queries (v4 Native)

Breakpoint vs Container

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

Container Query Usage

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

Angular Example

<!-- Angular component template -->
<div class="@container">
  <div class="card @sm:card-side @lg:grid @lg:grid-cols-2">
    <!-- Responds to parent width, not viewport -->
    <!-- Use when same component appears in sidebar AND full-width page -->
  </div>
</div>

When to Use

ScenarioUse
Page-level layoutsViewport breakpoints
Component-level responsiveContainer queries
Reusable Angular componentsContainer queries (context-independent)

4. Responsive Design

Breakpoint System

PrefixMin WidthTarget
(none)0pxMobile-first base
sm:640pxLarge phone / small tablet
md:768pxTablet
lg:1024pxLaptop
xl:1280pxDesktop
2xl:1536pxLarge 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

MethodBehaviorUse When
class.dark class togglesManual theme switcher
mediaFollows system preferenceNo user control
selectorCustom selector (v4)Complex theming
daisyUI data-themeSemantic token swapAngular workspace standard

daisyUI Dark Mode (Angular Workspace Standard)

// theme.service.ts — daisyUI approach (workspace standard)
@Injectable({ providedIn: 'root' })
export class ThemeService {
  setTheme(theme: 'light' | 'dark'): void {
    document.documentElement.setAttribute('data-theme', theme);
    localStorage.setItem('theme', theme);
  }
}
<!-- All daisyUI semantic classes switch automatically — no per-component CSS needed -->
<div class="bg-base-100 text-base-content">
  <!-- bg-base-100 is white in light, dark in dark theme automatically -->
</div>

Raw Tailwind Dark Mode Pattern (non-daisyUI)

ElementLightDark
Backgroundbg-whitedark:bg-zinc-900
Texttext-zinc-900dark:text-zinc-100
Bordersborder-zinc-200dark:border-zinc-700

6. Modern Layout Patterns

Flexbox Patterns

PatternClasses
Center (both axes)flex items-center justify-center
Vertical stackflex flex-col gap-4
Horizontal rowflex gap-4
Space betweenflex justify-between items-center
Wrap gridflex flex-wrap gap-4

Grid Patterns

PatternClasses
Auto-fit responsivegrid grid-cols-[repeat(auto-fit,minmax(250px,1fr))]
Asymmetric (Bento)grid grid-cols-3 grid-rows-2 with spans
Sidebar layoutgrid grid-cols-[auto_1fr]

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


7. Modern Color System

OKLCH vs RGB/HSL

FormatAdvantage
OKLCHPerceptually uniform, better gradients and hover states
HSLIntuitive hue/saturation
RGBLegacy compatibility

OKLCH for daisyUI Custom Themes

/* Custom daisyUI theme using OKLCH — produces better hover gradients */
@plugin "daisyui" {
  themes: [{
    mytheme: {
      "primary": "oklch(0.65 0.20 280)",   /* Brand purple */
      "secondary": "oklch(0.70 0.15 200)", /* Teal */
      "accent": "oklch(0.75 0.18 160)",
      "base-100": "oklch(0.98 0 0)",
      "base-content": "oklch(0.20 0 0)",
    }
  }]
}

Color Token Architecture

LayerExamplePurpose
Primitive--blue-500Raw color values
Semantic--color-primaryPurpose-based naming
Component--button-bgComponent-specific

In Angular: use daisyUI semantic classes (bg-primary, text-base-content) — never primitives directly.


8. Typography System

Font Stack Pattern

TypeRecommended
Sans'Inter', 'SF Pro', system-ui, sans-serif
Mono'JetBrains Mono', 'Fira Code', monospace
Display'Outfit', 'Poppins', sans-serif

Type Scale

ClassSizeUse
text-xs0.75remLabels, captions
text-sm0.875remSecondary text
text-base1remBody text
text-lg1.125remLead text
text-xl+1.25rem+Headings

9. Animation & Transitions

Built-in Animations

ClassEffect
animate-spinContinuous rotation
animate-pingAttention pulse
animate-pulseSubtle opacity pulse
animate-bounceBouncing effect

Transition Patterns

PatternClasses
All propertiestransition-all duration-200
Specifictransition-colors duration-150
With easingease-out or ease-in-out
Hover effecthover:scale-105 transition-transform

10. Component Extraction

When to Extract

SignalAction
Same class combo 3+ timesExtract component
Complex state variantsExtract component
Design system elementExtract + document

Extraction Methods

MethodUse When
Angular component / daisyUI component variantDynamic, needs Angular bindings or daisyUI variant classes
@apply in CSSStatic, no JS needed
Design tokensReusable values

11. Anti-Patterns

Don'tDo
Arbitrary values everywhereUse design system scale
!importantFix specificity properly
Inline style=Use utilities
Duplicate long class listsExtract component
Mix v3 config with v4Migrate fully to CSS-first
Use @apply heavilyPrefer components
Use tailwind.config.js in v4Use @theme {} in CSS
Copy v3 Stack Overflow examplesVerify against v4 docs

12. Performance Principles

PrincipleImplementation
Purge unusedAutomatic in v4
Avoid dynamismNo template string classes
Use OxideDefault in v4, 10x faster
Cache buildsCI/CD caching

Related Skills

  • angular-spa — Angular 21.x implementation with full daisyUI v5.5.5 and Tailwind v4 reference files
  • angular-best-practices — OnPush, Signals, bundle optimization, @defer
  • design-system — token enforcement (Angular + Flutter)
  • web-performance-optimization — bundle size, CSS purging, LCP

Additional Resources


Verify Step

Before delivering any Tailwind changes:

  1. Confirm no tailwind.config.js was created — v4 uses @theme {} in CSS only
  2. Grep changed templates: grep -n "bg-blue-\|text-blue-\|bg-red-" <file> — zero raw primitive colors in Angular templates
  3. Grep for arbitrary values: grep -c "\[" <file> — minimize; each must be justified
  4. Confirm dark mode uses data-theme attribute swap (daisyUI), not dark: prefixes, unless project explicitly uses raw Tailwind dark mode
  5. Run ng build to confirm the Oxide compiler picks up all classes (no purged classes)

Remember: Tailwind v4 is CSS-first. Use @theme {} not tailwind.config.js. Use daisyUI semantic tokens in Angular templates — never raw Tailwind primitives like bg-blue-500.

我的收藏