CSS中,*
会匹配任何元素。
通常情况下,*|*
会被用来代替*
来匹配所有元素。这种情况一般用于测试目的。
*
和*|*
在CSS中有什么区别?
CSS中,*
会匹配任何元素。
通常情况下,*|*
会被用来代替*
来匹配所有元素。这种情况一般用于测试目的。
*
和*|*
在CSS中有什么区别?
*
和*|*
并不总是相同的。如果提供了默认名称空间,则*
仅选择属于该名称空间的元素。
You can visually see the differences using the below two snippets. In the first, a default namespace is defined and so the *
selector applies the beige colored background only to the element which is part of that namsepace whereas the *|*
applies the border to all elements.
@namespace "http://www.w3.org/2000/svg";
* {
background: beige;
}
*|* {
border: 1px solid;
}
<a href="#">This is some link</a>
<svg xmlns="http://www.w3.org/2000/svg">
<a xlink:href="#">
<text x="20" y="20">This is some link</text>
</a>
</svg>
*
和*|*
都适用于所有元素,因此所有元素都具有米色背景和黑色边框。换句话说,在未指定默认命名空间时,它们的工作方式是相同的。
* {
background: beige;
}
*|* {
border: 1px solid;
}
<a href="#">This is some link</a>
<svg xmlns="http://www.w3.org/2000/svg">
<a xlink:href="#">
<text x="20" y="20">This is some link</text>
</a>
</svg>
http://www.w3.org/1999/xhtml
。Firefox遵循这种行为,并且在所有HTML5用户代理中保持一致。您可以在this answer中找到更多信息。
*|*
的含义是什么? - Flimm