Chuyển đến nội dung
Skillpedia
Website và giao diện (frontend)75k · #3031

specificity-management

Skill này làm gì

Skill này rà soát một stylesheet để tìm bộ chọn có độ đặc hiệu cao, lồng nhau sâu và cờ important không cần thiết, rồi đơn giản hóa chúng. Nó dành cho lập trình viên front-end thấy kiểu dáng khó thay đổi.

Khi nào nên dùng

  • ✓Khi bạn yêu cầu agent dọn một stylesheet khó ghi đè.
  • ✓Khi lập trình viên liên tục thêm !important để kiểu dáng hoạt động.
  • ✓Khi kiểu dáng của các thành phần xung đột vì bộ chọn quá đặc hiệu hoặc lồng quá sâu.

Liên kết skill

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

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/specificity-management/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Stylesheet của tôi đầy !important và bộ chọn ID, và mỗi lần sửa lại làm hỏng thứ khác. Bạn có thể đơn giản hóa nó không?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent tìm các kiểu dáng dựa trên ID, bộ chọn lồng sâu và cờ !important không cần thiết. Nó thay chúng bằng bộ chọn class, giảm độ lồng và dùng các mẫu có độ đặc hiệu bằng không như :where() khi phù hợp.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Keep CSS specificity low and flat

High specificity creates an escalation problem — once you use an ID selector, you need another ID to override it. Developers respond with !important, which escalates further. Flat, low-specificity CSS is predictable: later rules and more-specific selectors win cleanly, and the cascade works as intended.

Quick Reference

  • Prefer class selectors over ID selectors for styling
  • Avoid nesting selectors more than 3 levels deep
  • Never use !important except as a last resort for utility overrides
  • Use :where() to apply styles with zero specificity

Check

Analyze the selectors in this CSS file for specificity issues: ID selectors used for styling, overly nested selectors, and unnecessary !important.

Fix

Flatten high-specificity selectors to use classes instead of IDs, reduce nesting depth, and remove unnecessary !important declarations.

Explain

Explain CSS specificity scoring, why high specificity causes maintenance problems, and how to keep specificity flat using classes and BEM.

Code Review

Review stylesheets, component styles, and responsive states related to Keep CSS specificity low and flat. 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/specificity-management

Câu hỏi thường gặp

Độ đặc hiệu là gì?

Đó là điểm số mà trình duyệt dùng để quyết định quy tắc CSS nào thắng khi nhiều quy tắc cùng khớp một phần tử.

Tại sao !important là vấn đề?

Skill cho biết nó làm vấn đề leo thang, vì lần ghi đè tiếp theo thường lại cần một !important khác.

BEM giúp ích thế nào?

Skill cho biết tên class theo BEM giữ độ đặc hiệu ở mức phẳng và làm cascade dễ đoán hơn.

Chi tiết

Mô tả gốc của tác giả

Use when reviewing stylesheets, component styles, and responsive behavior related to Keep CSS specificity low and flat. Check the rendered layout across breakpoints and interaction states before proposing a fix.

repo: thedaviddias/Front-End-Checklist

Độ phổ biến

Sao GitHub
75k
Vị trí xếp hạng
#3031
Giấy phép
MIT
Cập nhật
31/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự