css通用选择器用_通用选择器(CSS选择器)

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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值