跳到主要內容

宣告屬性單位允許清單

在宣告中指定允許的屬性和單位配對清單。

a { width: 100px; }
/** ↑ ↑
* These properties and these units */

message 次要選項 可以接受此規則的參數。

選項

物件{ "未加前綴的屬性名稱": ["陣列", "of", "單位"]|"單位" }

如果屬性名稱以 "/" 圍繞(例如 "/^animation/"),則會將其解釋為正規表示式。這允許輕鬆地鎖定速記,例如:/^animation/ 將會比對 animationanimation-durationanimation-timing-function 等。

給定

{
"font-size": ["em", "px"],
"/^animation/": "s",
"line-height": []
}

以下模式被視為問題

a { font-size: 1.2rem; }
a { animation: animation-name 500ms ease; }
a { -webkit-animation: animation-name 500ms ease; }
a { animation-duration: 500ms; }
a { line-height: 13px; }

以下模式不是被視為問題

a { font-size: 1em; }
a { height: 100px; }
a { animation: animation-name 5s ease; }
a { -webkit-animation: animation-name 5s ease; }
a { animation-duration: 5s; }
a { line-height: 1; }

選用的次要選項

ignore: ["inside-function"]

忽略函式內的單位。

例如,給定

[
{
"/^border/": ["px"],
"/^background/": ["%"]
},
{
"ignore": ["inside-function"]
}
]

以下模式不是被視為問題

a {
border: 1px solid hsla(162deg, 51%, 35%, 0.8);
}
a {
background-image: linear-gradient(hsla(162deg, 51%, 35%, 0.8), hsla(62deg, 51%, 35%, 0.8));
}