星号/body颜色的特异性/继承?

Specificity / inheritance of color from asterisk / body?

我对以下内容有点困惑css

* {
    color: yellow;
}
body {
    color: black;
}

和HTML

    <div>
        <p> Test text... </p>

    </div>

body 下的任何 "p" 都会变成黄色 - 但为什么呢?星号没有权重。

并且颜色是继承的,所以为什么我的 "p" 的颜色不采用 body 的颜色?

而是使用星号中的颜色。

我的意思是,如果 "body" 和 "p"(以及继承线中的任何东西)没有颜色,那么它应该使用星号。

有人可以帮忙吗?为什么上面是这样。

上面 html 的块是黄色的,但为什么没有黑色(来自 body)?

I mean, if a "body" and "p" (and anything in the line of inheritance) doesn't have a background-color then it should use the asterisk.

星号是选择器的一部分,表示 "any element",而不是表示其中的属性在没有继承或指定值时作为默认值应用的特殊规则。

例如,匹配 body(还有 head)的另一种方法是:

html > * {
    …
}

因为 body 一个元素 (*),它是 (>) 一个名为“html” (html).

因此,您的 body 规则将背景颜色应用于正文,但您的 * 规则将背景颜色应用于 p

(背景颜色也不是继承的 属性,但在这种情况下无关紧要。color 的行为相同。)