跳至正文
OpenAgentSkill
浏览已开放 · 目录记录日期 2026-11-21 · 自动更新和账户服务暂时关闭。
设计与 UI

css

CSS conventions, layout systems, and modern patterns: predictable styles through low specificity and explicit cascade control. Invoke whenever task involves any interaction with CSS code — writing, reviewing, refactoring, debugging, or understanding stylesheets, SCSS, layout, or responsive design.

xobotyi · 已有静态检查记录

安装与使用

运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。

npx skills add xobotyi/cc-foundry --skill css

技能说明


name: css description: >- CSS conventions, layout systems, and modern patterns: predictable styles through low specificity and explicit cascade control. Invoke whenever task involves any interaction with CSS code — writing, reviewing, refactoring, debugging, or understanding stylesheets, SCSS, layout, or responsive design.

CSS

Predictability is the highest CSS virtue. If your styles require !important to work, restructure the cascade.

CSS rewards explicit, low-specificity selectors and intentional cascade ordering. Prefer boring, readable patterns over clever one-liners.

References

  • Layout — [${CLAUDE_SKILL_DIR}/references/layout.md]: Flex shorthand values, grid details (subgrid, implicit rows, alignment), layout patterns
  • Modern CSS — [${CLAUDE_SKILL_DIR}/references/modern-css.md]: Extended modern CSS patterns and examples
  • SCSS — [${CLAUDE_SKILL_DIR}/references/scss.md]: @forward patterns, module configuration, built-in modules, file organization
  • Responsive — [${CLAUDE_SKILL_DIR}/references/responsive.md]: Extended responsive design patterns and examples
  • Methodologies — [${CLAUDE_SKILL_DIR}/references/methodologies.md]: Methodology patterns and architecture details

Selectors and Specificity

  • Single class selectors by default — keep specificity flat at 0-1-0
  • Never use ID selectors for styling — IDs are for anchors and JS hooks
  • Never qualify classes with elements — .error not div.error
  • Max nesting depth: 3 levels — deeper nesting couples CSS to DOM structure
  • Avoid !important — use cascade layers or restructure selectors instead; only valid use is in a low-priority reset layer for truly essential styles
  • Use :where() to zero-out specificity when needed — :where(.card) .title has 0-0-1 specificity
  • Use :is() with awareness — it takes the highest specificity of its arguments
  • Flatten nested selectors in SCSS — ability to nest does not mean you should

Layout Systems

Choosing Flexbox vs Grid

Use CaseSystem
One-dimensional flow (row or column)Flexbox
Two-dimensional layout (rows AND columns)Grid
Content-driven sizingFlexbox
Layout-driven sizingGrid
Component internals (nav items, card content)Flexbox
Page-level structure, complex arrangementsGrid
Items need to wrap naturallyFlexbox
Precise placement on named lines/areasGrid

Both work together — a grid item can be a flex container and vice versa.

Flexbox

  • Always use the flex shorthand — it sets intelligent defaults. See ${CLAUDE_SKILL_DIR}/references/layout.md for the full shorthand value table
  • flex-flow: row wrap combines flex-direction and flex-wrap
  • Use flex-wrap with a flex basis for responsive layouts without media queries: flex: 1 1 300px wraps items when they can't maintain 300px minimum
  • Centering: display: flex; align-items: center; justify-content: center or margin: auto on a flex child
  • gap over margin hacks — works in both flexbox and grid
  • Avoid justify-content: space-between with wrap — causes orphan gaps; prefer gap + flex-wrap

CSS Grid

  • repeat(auto-fit, minmax(250px, 1fr)) is the canonical responsive grid — no media queries needed
  • Prefer auto-fit over auto-fill — auto-fit expands columns to fill space; auto-fill keeps empty tracks
  • Use named grid areas for page-level layouts — they auto-create named lines
  • Never hardcode px widths on grid items — use fr, minmax(), or auto
  • grid-auto-flow: dense fills visual holes — use carefully, it breaks visual/source order alignment (a11y concern)
  • Never use order in ways that break logical reading order
  • See ${CLAUDE_SKILL_DIR}/references/layout.md for subgrid, implicit rows, alignment shorthands, and negative line numbers

General Layout Rules

  • Never use float for layout — floats are for wrapping text around images
  • Intrinsic sizing first — use flex-wrap, min(), max(), clamp() before reaching for media queries

CSS Nesting

  • Use & for pseudo-classes/elements and compound selectors — &:hover, &::before, &.active
  • Omit & for descendant selectors — .card { .title {} } works
  • & is required when the nested selector starts with a type selector — & p {} not p {}
  • Nesting at-rules (@media, @supports, @container) nest directly inside rules
  • Specificity: :is() wrapping applies in nesting — be aware that specificity may differ from the equivalent unnested selector
  • Max depth: 3 levels — same rule as flat CSS

Cascade Layers (@layer)

  • Declare all layers at the top of the stylesheet in a single statement: @layer reset, defaults, themes, components, utilities;
  • First declared = lowest priority; un-layered styles always beat layered styles
  • !important reverses layer order — !important in the lowest layer wins over !important in higher layers
  • Import third-party CSS into sub-layers: @import url('vendor.css') layer(vendor.bootstrap);
  • Use revert-layer to roll back to the previous layer's value
  • !important in low layers is intentional — it means "this style is essential, don't override"
  • Don't create layers per-component — layers manage cascade priority between categories (reset vs component vs utility), not scope
  • Nested layers: @layer components { @layer buttons, cards; } — access via @layer components.buttons
  • Anonymous layers (@layer { }) can't be appended to later

Container Queries

  • Define containment: container-type: inline-size on the wrapper
  • Name containers for targeting: container: card / inline-size
  • Query by name: @container card (width > 400px) { }
  • Unnamed queries hit the nearest ancestor container

Container Query Units

  • cqw
阅读完整来源 ↗