个人博客链接:https://blog.retechs.cn/1016.html
在推特上浏览的时候看到一个很有意思的css试题,试题类型为css的特异性;
How well do you know CSS?
Given these classes:
.red {
color: red;
}
.blue {
color: blue;
}
Which color would these divs be?
<div class=”red blue”>
<div class=”blue red”>
1.First red, second blue
2.First blue, second red
3.Both blue
4.Both red
到现在为止,投票率分别为9%,44%,43%,3%;
通过投票率可以看出大部分人选择第一个蓝色,第二个红色,其实正确的结果为3,全是蓝色,在css中当多个声明具有相同的特异性时, 在 CSS 中找到的最后一个声明将应用于该元素,
应用于元素的类的顺序无关紧要。
参考链接:https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity (css的特异性)