首先看两篇文章:
一:https://www.cnblogs.com/wangmeijian/p/4207433.html.
二:http://www.nowamagic.net/csszone/css_SeletorPriorityRules.php
总结:
权重:
通配选择器:0,0,0,0,0 ()
元素和伪元素:0,0,0,0,1(例如div;p; :first-line)
类选择器,伪类,属性选择器:0,0,0,1,0
(例如:hover;.main;input[type=“text”])
ID选择器:0,0,1,0,0(例如#main)
内联样式:0,1,0,0,0(style="“)
!importangt:1,0,0,0,0
举例:
.demo input[type="text]{…}
0,0,0,2,1
div #demo a{…}
0,0,1,0,2
.demo input[type=“text”]{color: blue;}
0,0,0,2,0
div#main-content div.paragraph h2.first{…}
0,0,1,2,3