首页 > Web开发 > 详细

[CSS3] Understand CSS Selector Specificity

时间:2018-12-11 10:40:44      阅读:247      评论:0      收藏:0      [点我收藏+]

It is hard to explain css selector specificty, to easy way to understand it is by playing around with it.

 

To remember some rules can be helpful:

  • inline style > ID selector > Classes, attributes, and pseudo-classes > Elements and pseudop elements

Which means if you have inline style in your html, even you try to use ID selector, it cannot override the inline style. That‘s why people recommend don‘t use inline style because it is hard to override.

 

  • If one combine selector A has more specificty than the other B, A will override B, even B comes later.

技术分享图片

First one is the winner. 

 

  • If A and B has the same specificity, B comes later win.
  • !Important overrides all the rest. This is the most powerful one, but again it is hard to override in the future if needed, recommended not to use it as much as possible. 

[CSS3] Understand CSS Selector Specificity

原文:https://www.cnblogs.com/Answer1215/p/10100201.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!