302-css-best-practices

302-css-best-practices is a cursor rule for Cursor from HaiDong-Once/cursor-rules-collection. It costs 0 tokens per session (2,152 once invoked), scanned A, original, MIT.

A set of rules for writing CSS, the language that controls how web pages look. It covers formatting, naming, selectors, and property order.

In plain words
What is it for?
Use it when creating or reviewing CSS for websites and web applications, especially when a team needs shared style conventions.
Why use it?
It keeps styles consistent and easier to read, maintain, and update. It also helps avoid overly complex selectors and some performance problems.

Cursor rule for Cursor

Written for Cursor: a Cursor rule (.mdc).

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/haidong-once/cursor-rules-collection/302-css-best-practices
Clone the repo
git clone --depth 1 https://github.com/HaiDong-Once/cursor-rules-collection

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for 302-css-best-practices

README.md
[![agentmods](https://agentmods.dev/badge/rules/haidong-once/cursor-rules-collection/302-css-best-practices.svg)](https://agentmods.dev/rules/haidong-once/cursor-rules-collection/302-css-best-practices)
Your own site
<a href="https://agentmods.dev/rules/haidong-once/cursor-rules-collection/302-css-best-practices"><img src="https://agentmods.dev/badge/rules/haidong-once/cursor-rules-collection/302-css-best-practices.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 2,152 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00000 $0.02152
Opus 5 $0.00000 $0.01076
Sonnet 5 $0.00000 $0.00430
Haiku 4.5 $0.00000 $0.00215

Measured 6d ago against content hash c4b27cafee15, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

302-css-best-practices scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 6d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

frontend/302-css-best-practices.mdc · 400 lines

How it starts

The opening of the file, as written. The whole thing — 400 lines — stays where its author put it; the contents beside it link to each section on GitHub.

CSS最佳实践规范 (302)

规则概述

本规范定义了CSS的编码规范和最佳实践,旨在提高样式代码的可读性、可维护性和性能。

基本规范

1.1 代码格式

  • 缩进使用2个空格(一个tab)
  • 每个属性声明末尾都要加分号
  • 选择器和声明块之间使用一个空格
  • 每个属性单独一行
/* 推荐 */
.selector {
  property1: value1;
  property2: value2;
}

/* 不推荐 */
.selector{property1:value1;property2:value2;}

1.2 命名规范

  • 类名使用有意义的命名,反映元素用途而非外观
  • 使用连字符(-)作为类名中单词的分隔符
  • 避免使用下划线(_)和驼峰式命名
  • ID和类名小写
/* 推荐 */
.nav-item {
  margin-right: 10px;
}

/* 不推荐 */
.navItem {
  margin-right: 10px;
}

/* 不推荐 - 基于表现而非用途 */
.blue-button {
  background-color: blue;
}

/* 推荐 - 基于用途 */
.btn-primary {
  background-color: blue;
}

选择器规范

2.1 选择器性能

  • 避免使用通配符选择器(*)
  • 避免使用标签名作为选择器
  • 使用直接子选择器优化性能
  • 选择器嵌套层级不超过3层
/* 不推荐 - 标签选择器 */
div a span {
  color: red;
}

/* 推荐 - 使用类选择器 */
.menu .menu-link .icon {
  color: red;
}

/* 更好 - 使用直接子选择器减少层级 */
.menu > .menu-link > .icon {
  color: red;
}

/* 最佳 - 扁平化选择器 */
.menu-icon {
  color: red;
}

2.2 避免使用ID选择器

  • 尽量使用类选择器,避免使用ID选择器(高特异性会导致样式难以覆盖)
/* 不推荐 */
#header {
  padding: 20px;
}

/* 推荐 */
.header {
  padding: 20px;
}

属性规范

3.1 属性顺序

按照特定的顺序组织属性,提高代码可读性:

  1. 布局属性(position, display, float 等)
  2. 盒模型属性(width, height, margin, padding 等)
  3. 视觉属性(background, border, box-shadow 等)
  4. 文字排版(color, font, text-align, text-transform 等)
  5. 其他属性
.element {
  /* 布局属性 */
  position: absolute;
  display: block;
  float: left;
  
  /* 盒模型属性 */
  width: 100px;
  height: 100px;
  margin: 10px;
  padding: 10px;
  
  /* 视觉属性 */
  background: #f5f5f5;
  border: 1px solid #e5e5e5;
  border-radius: 3px;
  
  /* 文字排版 */
  color: #333;
  font-size: 16px;
  text-align: center;
  
  /* 其他 */
  cursor: pointer;
}

3.2 简写属性

  • 尽量使用简写属性
  • 省略值为0的单位
  • 十六进制值使用小写字母,尽可能使用简写
/* 不推荐 */
.element {
  margin-top: 0px;
  margin-right: 10px;
  margin-bottom: 20px;
  margin-left: 10px;
  background-color: #FFFFFF;
}

/* 推荐 */
.element {
  margin: 0 10px 20px;
  background-color: #fff;
}

组织规范

4.1 模块化CSS

  • 采用模块化方式组织CSS,每个组件维护自己的样式
  • 使用BEM命名约定(Block-Element-Modifier)提高可读性和可维护性

Read the full file on GitHub · 400 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 6d ago First seen · 400 lines · 0 tokens per session scan A c4b27cafee15

Subscribe to this mod's changes

302-css-best-practices is a cursor rule published in the GitHub repository HaiDong-Once/cursor-rules-collection (24 stars, last pushed 1y ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 2,152 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.