选择器分组 声明分组
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/
选择器分组 声明分组
相关资源:JAVA上百实例源码以及开源项目