AGENT SKILL

CSS 样式开发规范

css-styling

CSS Modules 约定、设计令牌、容器查询,以及 CSS 与组件的职责边界。适用场景:编辑本仓库中的任意 `*.css` / `*.module.css` 文件,或为新组件编写样式。

License 许可
CC-BY-4.0
最近更新
2026-11-14
Stars
★ 2
Forks
1

01 前言 Front Matter

name
css-styling
description
CSS Modules conventions, design tokens, container queries, and CSS-vs-component boundaries. USE WHEN: editing any `*.css` / `*.module.css` file in this repo, or writing styles for a new component.

03 SKILL.md 正文

CSS Editing Instructions

CRITICAL: Before Editing Any CSS File

REQUIRED STEP: Before making any changes to a .css file, you MUST read the corresponding .tsx file(s) that use it:

  1. Look for .tsx files with the same base name (e.g., ComponentName.tsx for ComponentName.module.css)
  2. Search for imports of the CSS file using grep with pattern: import.*from.*'\.\/.*\.module\.css'
  3. Read ALL .tsx files that import the CSS file before proceeding with edits

You may also need to edit the matching .tsx file and its structure to properly edit CSS.

CSS Architecture

This project uses CSS Modules. Component CSS files should be named *.module.css and placed alongside their corresponding .tsx component files. Existing app-level stylesheets in apps/prototype/app/styles/ are an exception for foundational styles such as resets and font registration; do not put component styles there.

Do not write inline css in the style attribute (unless there is a javascript value being attached).

Custom Fluent Components

Do not use CSS to recreate components that already exist in CoreAI or Fluent. Before editing components, invoke the prototype-app-react-components skill for proper component usage guidelines. Most appearance and interaction styles are already handled by documented CoreAI components and props. If an appropriate prop is available, use it instead of writing CSS.

CSS @layers

There are 3 named CSS @layers in this app, ordered base, griffel, and common, plus unlayered CSS (which is not a named layer). The base layer contains the foundational box-sizing reset in apps/prototype/app/styles/globals.css. The griffel layer encapsulates Fluent's styles through the app-owned layered renderer - NEVER write CSS into the griffel layer. The common layer is for common components inside the apps/prototype/app/components/common folder and existing app-level resets; all components in this folder should use this layer, and component styles outside it should not. All other component styles should be written outside of these layers.

General Guidelines

No Global CSS: Do not write global CSS selectors (e.g., body, h1) outside of a scoped CSS class for component styling. All component styles must be scoped using CSS Modules. Existing app-level stylesheets in apps/prototype/app/styles/ are a narrow exception for foundational resets, font registration, and app-wide variable defaults, not component styling. Use Nested Classes: Scope styles to specific elements within the component using nested class selectors. Avoid !important: Do not use !important in CSS rules. Instead, refactor the CSS or component structure to achieve the desired specificity.

Responsive Breakpoints — Container Queries

CRITICAL: Do NOT use @media (width ...) for responsive width breakpoints. Use @container app (width ...) instead.

This app uses CSS container queries so that responsive behavior responds to the actual available content width, not the viewport. Panels that reduce the content container's available width affect its breakpoints; the app-local floating feature selector is fixed-position and does not consume layout width.

The ContainerQueryProvider component (wrapping the app children with styles.fullscreenContainer in apps/prototype/app/components/shell/AppContent.tsx) establishes container-type: inline-size with container-name: app.

Correct — Container Query

@container app (width <= 768px) {
  .sidebar {
    display: none;
  }
}

Wrong — Viewport Media Query

/* ❌ DO NOT use @media for width breakpoints */
@media (width <= 768px) {
  .sidebar {
    display: none;
  }
}

When to still use @media

  • Height queries: @media (height <= 480px) — container queries only support inline-size
  • User preferences: @media (prefers-color-scheme: dark), @media (prefers-reduced-motion: reduce)
  • Accessibility: @media (forced-colors: active)
  • Elements in portals/top-layer: Dialogs, popovers, and other portal-rendered elements that exist outside the container tree (these still need viewport @media queries)

Layout

CSS should primarily be used for layout, spacing, borders, and backgrounds. Avoid using CSS for text styles, component styles, or interaction styles. Most of these are handled by React components and props. Prefer using flexbox with gap for most layouts instead of block with margin. Grid is acceptable for more complex layouts.

Reduce nesting of HTML elements where possible - prefer a flatter structure.

Text Styling

Text Properties: Avoid writing these CSS properties directly in CSS files. The components handle most of these by default.

  • font-size
  • font-weight
  • font-family
  • line-height
  • color (for text color)

EXCEPTION: Text properties inside @container queries for responsive typography (e.g., scaling a heading on mobile) should be kept in CSS — the Text component doesn't handle container-based sizing.

INSTEAD: Where these properties are applied to a Text, span, or other text element, refactor to use the documented Text component from @coreai-ds/react-components and replace any text CSS properties with preset and foreground props.

import { Text } from '@coreai-ds/react-components';

<Text preset="body" foreground={3}>
  Your text here
</Text>;

Text Component Presets & Foreground

Presets (size from smallest to largest):

  • bodyXS (10px) / bodyXSStrong (10px semibold)
  • bodyS (12px) / bodySStrong (12px semibold); heading6 is an alias of bodySStrong
  • body (14px) / bodyStrong (14px semibold); heading5 is an alias of bodyStrong
  • heading4 (16px semibold)
  • heading3 (20px semibold)
  • heading2 (28px semibold)
  • heading1 (40px semibold)

Foreground (text color intensity):

  • 1 - Headings
  • 2 - Body text
  • 3 - Subtle/muted/secondary
  • 4 - Disabled/placeholder
  • 'disabled' - Disabled text

Additional properties:

  • block - makes the text a block element
  • italic - makes the text italic
  • font - sets the font family - base | monospace
  • as - html element to render as (e.g., 'p', 'span', 'h1', etc.)

Don't use Fluent's fixed typography components (like <Body1> or <Title2>) directly. Always use CoreAI <Text> with preset and foreground props.

When you encounter these properties in existing CSS: Refactor the code to remove them from CSS and use the Text component in the .tsx file instead.

Combining CSS Classes

When applying multiple CSS classes, use the clsx utility:

import clsx from 'clsx';
import styles from './Component.module.css';

<div
  className={clsx(
    styles.class1,
    condition && styles.class2,
    className, // props.className mapped on to root element
  )}
/>;

CSS Variables

Use Fluent semantic color tokens directly.

Background

  • --colorNeutralBackground1 - Lighter primary background
  • --colorNeutralBackground2 - Middle background (uncommon)
  • --colorNeutralBackground3 - Darker background
  • --colorNeutralBackground4 - Very dark background (rarely used)

Border/Stroke

  • --colorNeutralBackground4 - Existing panel-divider color
  • --colorNeutralStroke1 - Standard border color for elements

Usage: border: 1px solid var(--colorNeutralStroke1);

Foreground/Text

Prefer using the Text component's foreground prop instead of setting text color in CSS.

  • --colorNeutralForeground1 - Intense (primary text/headings)
  • --colorNeutralForeground2 - Default body text color
  • --colorNeutralForeground3 - Subtle/muted (secondary text)
  • --colorNeutralForeground4 - Dim (disabled/placeholder text)
  • --colorBrandForeground1 - Brand color
  • --colorBrandForegroundLink - Link color

Interactive/States

Components own their hover, pressed, and selected states. Use the component API instead of introducing application-level interaction-color aliases.

Spacing - REQUIRED

NEVER use hardcoded pixel values or rem values for spacing values less than 32px. Always use these CSS variables:

  • --spacingNone (0)
  • --spacingXXS (2px)
  • --spacingXS (4px)
  • --spacingSNudge (6px)
  • --spacingS (8px)
  • --spacingMNudge (10px)
  • --spacingM (12px)
  • --spacingL (16px)
  • --spacingXL (20px)
  • --spacingXXL (24px)
  • --spacingXXXL (32px)
  • --spacingPagePadding - Special variable for horizontal page padding (adjusts by app container width, with a viewport-based fallback in the global stylesheet)

DO NOT use Fluent spacing variables that include "Horizontal" or "Vertical" in their names.

For pixel values 32px and above, you may use hardcoded values if necessary, but prefer using spacing variables where possible for consistency.

Border Radius

  • --borderRadiusNone (0)
  • --borderRadiusSmall (2px)
  • --borderRadiusMedium (4px)
  • --borderRadiusLarge (6px)
  • --borderRadiusXLarge (8px)
  • --borderRadius2XLarge (12px)
  • --borderRadius3XLarge (16px)
  • --borderRadius4XLarge (24px)
  • --borderRadius5XLarge (32px)
  • --borderRadius6XLarge (40px)
  • --borderRadiusCircular (9999px)

Example CSS Patterns

Good - Uses Variables

.container {
  padding: var(--spacingL);
  background-color: var(--colorNeutralBackground1);
  border: 1px solid var(--colorNeutralStroke1);
  gap: var(--spacingM);
}

Bad - Hardcoded Values

.container {
  padding: 16px; /* WRONG - use var(--spacingL) */
  background-color: #f5f5f5; /* WRONG - use var(--colorNeutralBackground1) */
  font-size: 14px; /* WRONG - use Text component instead */
  color: #333; /* WRONG - use Text component instead */
}

Summary Checklist

Before submitting CSS edits, verify:

  • [ ] Read corresponding .tsx file(s) that use this CSS
  • [ ] No text-styling properties (font-*, color) in CSS
  • [ ] All colors use Fluent semantic tokens
  • [ ] All spacing uses --spacing* variables
  • [ ] Width breakpoints use @container app (width ...) not @media (width ...)
  • [ ] Component CSS file is named *.module.css; any app-level stylesheet edit stays within the foundational-style exception
  • [ ] Classes combined with clsx when multiple are needed

04 同仓库更多 Skills

microsoft
microsoft/coreai-design-system

CoreAI React 组件开发

coreai-ds-fluentui-react

文档/技能 v0.1.1;包 v0.12.0。使用 @coreai-ds/react-components 构建、设置样式、审查或调试 React UI 时使用。通过 HTTPS 获取 CoreAI Markdown 文档,了解组件、API、默认值、模板、设计 token 和无障碍指南。

软件开发工程师前端开发与界面实现
★ 2
microsoft
microsoft/coreai-design-system

前端查询状态管理

state-management

CoreAI Sandbox 的简化版 TanStack Query + mock-JSON 数据层。使用场景:编辑数据获取 hooks(`app/hooks/use*.ts`)、在 `app/data/` 中添加模拟数据,或将组件接入查询状态。

软件开发工程师前端开发与界面实现
★ 2
microsoft
microsoft/coreai-design-system

开发服务器启动

start-app

启动 CoreAI Sandbox 开发服务器,并使用可用的浏览器工具将其打开。适用场景:用户要求“启动应用”、“运行开发服务器”、“打开应用”或“启动 CoreAI Sandbox”时。

软件开发工程师开发环境与工具链管理
★ 2
microsoft
microsoft/coreai-design-system

React Router 路由配置

routing

本 SPA 的 React Router v7 路由约定。适用场景:编辑 `app/routes.ts`、添加/删除路由或更改导航时。

软件开发工程师前端开发与界面实现
★ 2
microsoft
microsoft/coreai-design-system

React 组件使用与导入

react-components

CoreAI Sandbox 组件使用:导入边界、CoreAI MCP 文档以及本地适配器检查。适用场景:编辑任意 `*.tsx` 文件、选择组件或编写组件导入语句时。

软件开发工程师前端开发与界面实现
★ 2
microsoft
microsoft/coreai-design-system

新建设计变体

new-variant

使用内置的功能/变体系统为页面创建新的设计变体或备选方案。使用场景:设计师想尝试不同的布局、创建“方案 B”或“版本 2”、并排对比设计、添加 A/B 备选方案,或探索替代版本。不要构建自定义的切换方案。

界面设计师前端开发与界面实现
★ 2