选择器分组 声明分组_选择器分组

选择器分组 声明分组

We can group selectors using a comma (,) separator. The following declaration block will apply to any element that matches either of the selectors in the group:

我们可以使用逗号(,)分隔符对选择器进行分组。 以下声明块将应用于与组中任何一个选择器匹配的元素:

td, th {
  ⋮ declarations
}

We can think of the comma as a logical OR operator, but it’s important to remember that each selector in a group is autonomous. A common beginner’s mistake is to write groups like this:

我们可以将逗号视为逻辑OR运算符,但请务必记住,组中的每个选择器都是自治的。 初学者常见的错误是编写这样的组:

#foo td, th {
  ⋮ declarations
}

A beginner might think that the above declaration block will be applied to all td and th elements that are descendants of the element with an ID of “foo”. However, the selector group above is actually equivalent to this:

初学者可能会认为上述声明块将应用于ID为“ foo”的元素的所有后代td和th元素。 但是,上面的选择器组实际上等效于此:

#foo td {
  ⋮ declarations
}
th {
  ⋮ declarations
}

To achieve the true goal, write the selector group as follows:

为了实现真正的目标,请如下编写选择器组:

#foo td, #foo th {
  ⋮ declarations
}

Important: No Trailing Comma Needed Don’t leave a comma after the last selector in the group!

重要提示:不需要结尾逗号不要在组中的最后一个选择器后面留下逗号!

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

选择器分组 声明分组

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值