跳到正文
Skillpedia
网站与界面(前端)75k · #2797

css-custom-properties

它能做什么

这项技能检查样式表中是否有应该改为共享设计令牌的硬编码值。适合希望主题和全局样式修改变得简单的开发者。

适用场景

  • ✓当同一个颜色或间距值出现在许多地方时。
  • ✓当你想添加暗色模式或新的品牌主题时。
  • ✓当修改一个设计值需要编辑许多行代码时。

技能链接

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/css-custom-properties/SKILL.md

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

使用方法

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

可直接粘贴的消息

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

可以这样问 AI

“请把我样式表中重复出现的品牌颜色和间距值,提取为共享的自定义属性。”

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

工作原理

智能体会在根元素上把重复出现的值定义为自定义属性,并把每处硬编码的值替换为 var 引用,必要时提供备用值。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Use CSS custom properties for design tokens

Hard-coded color values and magic numbers scattered across CSS files make global changes (a rebrand, a dark mode, a spacing adjustment) require finding and updating dozens of individual lines. Custom properties centralize these values so one change propagates everywhere — and enable runtime theming that preprocessor variables cannot.

Quick Reference

  • Define reusable values as --variable-name on :root
  • Custom properties cascade and inherit — they can be overridden at any scope
  • Use var(--name, fallback) to provide fallback values
  • Custom properties are runtime values — JavaScript can read and write them

Check

Find hard-coded color values, spacing values, and font sizes in this CSS file that should be replaced with CSS custom properties.

Fix

Extract repeated and meaningful values into CSS custom properties on :root and replace all usages with var() references.

Explain

Explain CSS custom properties: how they differ from preprocessor variables, how cascade and inheritance work, and how to use them for theming.

Code Review

Review stylesheets, component styles, and responsive states related to Use CSS custom properties for design tokens. Flag exact selectors, declarations, or breakpoints that violate the rule in the rendered UI.


For full implementation details, code examples, and framework-specific guidance, see references/rule.md.

Rule page: https://frontendchecklist.io/rules/css/css-custom-properties

常见问题

自定义属性与预处理器变量有什么不同?

这项技能说明,它们是可以在任何作用域中被覆盖的运行时值,并且可以被 JavaScript 读取或修改。

它们能帮助实现暗色模式吗?

可以。这项技能说明,它们能实现预处理器变量无法做到的运行时主题切换。

备用值有什么作用?

如果没有设置该自定义属性,它会提供一个备用值。

详情

作者的原始描述

Use when reviewing stylesheets, component styles, and responsive behavior related to Use CSS custom properties for design tokens. Check the rendered layout across breakpoints and interaction states before proposing a fix.

repo: thedaviddias/Front-End-Checklist

热度

GitHub 星标
75k
排名
#2797
许可证
MIT
更新时间
2026/10/31

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能