gpt4 book ai didi

CSS 通用选择器 (*) 特性

转载 作者:行者123 更新时间:2023-12-04 14:25:25 29 4
gpt4 key购买 nike

我想弄清楚为什么 .x*.x具有更高的特异性当后者有望获胜时。

不是*.x应该具有 0-0-1-1 的特异性(1 个类,1 个标签)而 .x只是一个类(class) 0-0-1-0 ?

考虑以下基本代码:

*.x { color: blue; }

.x { color: red }
<p class="x">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque, nam.</p>


它应该是蓝色的。为了演示预期的行为,我替换了 *与另一个元素( p ):

p.x { color: blue; }

.x { color: red }
<p class="x">This time it works.</p>

最佳答案

universal selector ( * ) 对特定性没有影响,因此后一个选择器的样式将是应用的样式。

An asterisk (*) is the universal selector for CSS. It matches a single element of any type. Omitting the asterisk with simple selectors has the same effect. For instance, *.warning and .warning are considered equal.

关于CSS 通用选择器 (*) 特性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36643622/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com