css的优先级权重

选择器(优先级从高到低) 示例
  • 特殊性值 !important(重要性标识) div { color: #fff !important; } 无,但为了方便记忆,可将其表示为1,0,0,0,0
  • 行内样式 <div style="color: #fff;"></div> 1,0,0,0 id选择器 #id 0,1,0,0 类,
  • 伪类和属性选择器 .content, :first-child, [type="text"] 0,0,1,0
  • 标签和伪元素选择器 h1, ::after 0,0,0,1
  • 通配符、子选择器、相邻选择器 *, div > p, p + p 0,0,0,0
  • 继承 span { color: inherit; }
  • 浏览器默认值 浏览器开发者工具右侧的Styles面板中会显示user agent stylesheet字样 无
原文地址:https://www.cnblogs.com/chen-cheng/p/11949737.html