selector-max-specificity
限制选择器的特殊性。
¥Limit the specificity of selectors.
.foo, #bar.baz span, #hoo { color: pink; }
/** ↑ ↑ ↑
* Each of these selectors */
请访问 特异性计算器 以直观地展示选择器特异性。
¥Visit the Specificity Calculator for visual representation of selector specificity.
此规则忽略具有变量插值的选择器(#{$var}
、@{var}
、$(var)
)。
¥This rule ignores selectors with variable interpolation (#{$var}
, @{var}
, $(var)
).
此规则在计算选择器的特异性之前解析嵌套选择器。选择器列表 中的每个选择器都是单独评估的。
¥This rule resolves nested selectors before counting the specificity of a selector. Each selector in a selector list is evaluated separately.
message
次要选项 可以接受该规则的参数。
¥The message
secondary option can accept the arguments of this rule.
选项
¥Options
string
:允许的最大特异性。
¥string
: Maximum specificity allowed.
格式为 "id,class,type"
,如 W3C 选择器规范 中所述。
¥Format is "id,class,type"
, as laid out in the W3C selector spec.
例如,对于 "0,2,0"
:
¥For example, with "0,2,0"
:
以下模式被视为问题:
¥The following patterns are considered problems:
#foo {}
.foo .baz .bar {}
.foo .baz {
& .bar {}
}
.foo {
color: red;
@nest .baz .bar & {
color: blue;
}
}
以下模式不被视为问题:
¥The following patterns are not considered problems:
div {}
.foo div {}
.foo div {
& div a {}
}
.foo {
& .baz {}
}
.foo {
color: red;
@nest .baz & {
color: blue;
}
}
可选的辅助选项
¥Optional secondary options
ignoreSelectors: ["/regex/", /regex/, "non-regex"]
鉴于:
¥Given:
[
"0,2,0",
{
"ignoreSelectors": [":host", ":host-context", "/^my-/"]
}
]
以下模式不被视为问题:
¥The following patterns are not considered problems:
:host(.foo) .bar {}
:host-context(.foo.bar) {}
:host-context(.foo, :host(.bar).baz) {}
my-element.foo.bar {}
以下模式被视为问题:
¥The following patterns are considered problems:
:host(.foo) .bar.baz {}
:host-context(.foo.bar.baz) {}
:host-context(.foo, :host(.bar), .foo.bar.baz) {}
my-element.foo.bar.baz {}