项目
在 GitHub 查看
keeganstreet/specificity
关于
用于计算 CSS 选择器优先级的 JavaScript 模块。
网站与应用开发实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文Specificity Calculator
A JavaScript module for calculating and comparing the specificity of CSS selectors. The module is used on the Specificity Calculator website.
Note that version 1 is a complete re-write with support for CSS Selectors Level 4, and has a different API than earlier versions.
calculate(selector)
Parameters
selector:string- should be a valid CSS selector
Returns
A Specificity object with a type of Record<"A" | "B" | "C", number>.
Examples
calculate("#id");
{
A: 1,
B: 0,
C: 0
}
calculate(".classname");
{
A: 0,
B: 1,
C: 0
}
calculate("element");
{
A: 0,
B: 0,
C: 1
}
calculate('ul#nav li.active a');
{
A: 1,
B: 1,
C: 3
}
compare(a, b)
Parameters
a:Specificityobject with a type ofRecord<"A" | "B" | "C", number>b:Specificityobject with a type ofRecord<"A" | "B" | "C", number>
Returns
Returns a positive number if a has a higher specificity than b
Returns a negative number if a has a lower specificity than b
Returns 0 if a has the same specificity than b
Examples
[
"element",
".classname",
"#id",
]
.map(calculate)
.sort(compare);
[ { A: 0, B: 0, C: 1 }, { A: 0, B: 1, C: 0 }, { A: 1, B: 0, C: 0 } ]
compareDesc(a, b)
Same as compare but returns the opposite value, for use in sorting specificity objects with the highest specificity first.
探索相关项目
加载中…