使用通用选择器覆盖 CSS 重置

Overriding CSS Reset with the Univeral Selector

我有一个设置字体的重置(Eric Meyer 的重置),然后我在此之上加载我的样式表,我想在其中使用通用选择器全局设置字体

但是尽管在我的 SASS 中通用选择器是在 重置后 加载的,重置优先。 (请参阅来自 devtools 的附加屏幕截图)

我知道这与特异性有关,但我认为通用选择器会充当通配符。为什么是这样?

通用选择器 * 没有特异性值。基本上任何事情都优先于它。

通过 MDN:

The following list of selector types is by increasing specificity:

Universal selectors (e.g., *)

Type selectors (e.g., h1)

Class selectors (e.g., .example)

Attributes selectors (e.g., [type="radio"])

Pseudo-classes (e.g., :hover)

ID selectors (e.g., #example)

Inline style (e.g., style="font-weight:bold")

当然 !important 会覆盖以上所有内容,但也没有特定值。

可以在此处找到获取更多信息的良好来源:https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity