css通用选择器用

tech2023-01-04  102

css通用选择器用

描述 (Description)

The universal selector matches any element type. It can be implied (and therefore omitted) if it isn’t the only component of the simple selector. The two selector examples shown here are equivalent:

通用选择器匹配任何元素类型。 如果它不是简单选择器的唯一组成部分,则可以暗含(因此可以省略)。 此处显示的两个选择器示例是等效的:

*.warning { ⋮ declarations } .warning { ⋮ declarations }

It’s important not to confuse the universal selector with a wildcard character—the universal selector doesn’t match “zero or more elements.” Consider the following HTML fragment:

重要的是不要将通用选择器与通配符混淆—通用选择器不匹配“零个或多个元素”。 考虑以下HTML片段:

<body> <div> <h1>The <em>Universal</em> Selector</h1> <p>We must <em>emphasize</em> the following:</p> <ul> <li>It's <em>not</em> a wildcard.</li> <li>It matches elements regardless of <em>type</em>.</li> </ul> This is an <em>immediate</em> child of the division. </div> </body>

The selector div * em will match the following em elements:

选择器div * em将匹配以下em元素:

“Universal” in the h1 element (* matches the <h1>)

h1元素中的“通用”( *匹配<h1> )

“emphasize” in the p element (* matches the <p>)

p元素中的“强调”( *匹配<p> )

“not” in the first li element (* matches the <ul> or the <li>)

第一个li元素中的“ not”( *匹配<ul>或<li> )

“type” in the second li element (* matches the <ul> or the <li>)

第二个li元素中的“ type”( *匹配<ul>或<li> )

However, it won’t match the <em>immediate</em> element, since that’s an immediate child of the div element—there’s nothing between <div> and <em> for the * to match.

但是,它不会匹配<em>immediate</em>元素,因为它是div元素的直接子元素-在<div>和<em>之间没有任何要匹配的* 。

(Example)

This rule set will be applied to every element in a document:

此规则集将应用于文档中的每个元素:

* { margin: 0; padding: 0; }

翻译自: https://www.sitepoint.com/universal-selector-css-selector/

css通用选择器用

最新回复(0)