<html>
<style type = "text/css">
.red {
color: red ;
}
.blue {
color: blue;
}
</style>
<body>
<p class="red">this is red</p>
<p class="blue">this is blue</p>
<p class="red blue"> this is what </p>
<p class="blue red"> this is what </p>
<p class="red red"> this is what </p>
</body>
</html>
前两个p tag的颜色毫无疑问。 对于第三个和第四个p, 两个不同的class selector分别维护了不同的颜色,则在css文件里后出现的selector优先级更高,和class在p tag中出现的先后顺序无关。
如果css里先出现的red selector加上了!important的属性,则虽然red selector先出现,但其优先级也得到提升,大于blue selector: