当多个规则都可能对元素应用样式时,两个机制决定了结果:cascade(哪个规则获胜)和 inheritance(哪些属性从父元素传递给子元素)。
Cascade — 按优先级顺序解决冲突
浏览器通过按以下优先级顺序检查来选择获胜的声明:
text
1. Importance → !important beats normal declarations
2. Specificity → more specific selector wins (ids > classes > elements)
3. Source order → if still tied, the LAST rule defined wins
css
{ : blue; }
{ : green; }
{ : red; }
