Files
nexus/wiki/concepts/CSS-Design-System.md
2026-05-03 05:42:12 +08:00

2.2 KiB
Raw Blame History

title, type, tags, sources, last_updated
title type tags sources last_updated
CSS Design System concept
css
design-system
frontend
architecture
design-ux-architect.md
2026-04-24

Definition

CSS Design System 是一套结构化的 CSS 架构规范,通过 CSS Custom PropertiesCSS 变量)定义颜色、排版、间距等基础设计 Token供整个项目复用确保视觉一致性和主题切换能力。

Core Components

Color System

:root {
  /* Light Theme Colors */
  --bg-primary: [spec-light-bg];
  --bg-secondary: [spec-light-secondary];
  --text-primary: [spec-light-text];
  --text-secondary: [spec-light-text-muted];
  --border-color: [spec-light-border];

  /* Brand Colors */
  --primary-color: [spec-primary];
  --secondary-color: [spec-secondary];
  --accent-color: [spec-accent];
}

Typography Scale

:root {
  --text-xs: 0.75rem;   /* 12px */
  --text-sm: 0.875rem;  /* 14px */
  --text-base: 1rem;    /* 16px */
  --text-lg: 1.125rem;  /* 18px */
  --text-xl: 1.25rem;   /* 20px */
  --text-2xl: 1.5rem;   /* 24px */
  --text-3xl: 1.875rem; /* 30px */
}

Spacing System

:root {
  --space-1: 0.25rem;   /* 4px */
  --space-2: 0.5rem;    /* 8px */
  --space-4: 1rem;      /* 16px */
  --space-6: 1.5rem;    /* 24px */
  --space-8: 2rem;      /* 32px */
  --space-12: 3rem;     /* 48px */
  --space-16: 4rem;     /* 64px */
}

Theme Support

CSS Design System 必须原生支持三种主题模式:

  • Light Theme:浅色背景,深色文字
  • Dark Theme:深色背景,浅色文字
  • System Themeprefers-color-scheme 检测系统偏好
[data-theme="dark"] {
  --bg-primary: [spec-dark-bg];
  --bg-secondary: [spec-dark-secondary];
  --text-primary: [spec-dark-text];
  --text-secondary: [spec-dark-text-muted];
  --border-color: [spec-dark-border];
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-primary: [spec-dark-bg];
    /* ... */
  }
}

Sources