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

naming-conventions

它能做什么

这项技能检查 CSS 类名,并建议统一的命名规则,例如 BEM。适用于希望样式易于查找和修改的前端开发者和团队。

适用场景

  • ✓当你请智能体整理或统一 CSS 类名的时候。
  • ✓当很难看出某个类名的作用,而且各组件之间的样式不断冲突的时候。
  • ✓当你开始新项目,希望从一开始就有清晰的命名约定的时候。

技能链接

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/naming-conventions/SKILL.md

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

使用方法

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

可直接粘贴的消息

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

可以这样问 AI

“我的 CSS 类名很乱。请帮我用 BEM 这样统一的规则重新命名。”

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

工作原理

智能体会检查样式表中的类名,并将其改写为块、元素和修饰符的形式。它会让名称保持 kebab-case 格式,并把工具类与组件样式分开。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Use consistent CSS naming conventions

Without a naming convention, class names become a guessing game — does .active mean the nav item is active, the button is pressed, or a form field has focus? With BEM or a similar methodology, .button--active is unambiguous. This reduces the time spent searching for existing styles and prevents accidental style conflicts.

Quick Reference

  • BEM (Block__Element--Modifier) is the most widely adopted naming convention
  • Consistent naming lets you understand a class's purpose without reading its styles
  • Namespace utility classes and JS hooks separately from component styles
  • Use kebab-case for class names (not camelCase or snake_case)

Check

Audit the class names in this CSS file. Are they consistently named? Do they follow a clear convention? Are there any ambiguous names that could conflict?

Fix

Rename classes to follow BEM methodology: Block, Block__Element, Block--Modifier pattern.

Explain

Explain BEM naming convention, why naming conventions matter, and how to apply BEM to a real component.

Code Review

Review stylesheets, component styles, and responsive states related to Use consistent CSS naming conventions. 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/naming-conventions

常见问题

什么是 BEM?

BEM 代表 Block、Element 和 Modifier(块、元素和修饰符),它让类名有清晰的结构,例如 button--active。

为什么使用 kebab-case?

这项技能推荐它,而不是 camelCase 或 snake_case,以保持类名统一。

JavaScript 钩子需要单独的名称吗?

需要。这项技能建议把 JavaScript 钩子放在自己的命名空间中,与组件样式分开。

详情

作者的原始描述

Use when reviewing stylesheets, component styles, and responsive behavior related to Use consistent CSS naming conventions. Check the rendered layout across breakpoints and interaction states before proposing a fix.

repo: thedaviddias/Front-End-Checklist

热度

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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能