css:选择器权重和层叠顺序

选择器优先级

important > 内联 > ID > 类 >伪类 | 属性选择 | 标签> 伪元素 > 通配符 > 继承

  • 通配选择符的权值 0,0,0,0
  • 伪元素选择的权值为 0,0,0,1
  • 标签的权值为 0,0,0,1
  • 属性选择的权值为 0,0,1,0
  • 伪类选择的权值为 0,0,1,0
  • 类的权值为 0,0,1,0
  • ID的权值为 0,1,0,0
  • important的权值为最高 1,0,0,0

又max-width、min-width的超越最大

256个class选择器干翻id选择器的例子,在ie中有效
https://www.zhangxinxu.com/study/201208/256-class-fire-an-id.html


层叠顺序

正z-index > z-index:auto|0 > inline > float > block > 负z-index > background/border

z-index在css3中已经并非只对定位元素有效了

猜你喜欢

转载自blog.csdn.net/weixin_42519137/article/details/86740468
今日推荐