跳到主要內容

單位允許清單

指定允許的單位清單。

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

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

選項

陣列|字串["陣列", "of", "單位"]|"單位"

給定

["px", "em", "deg"]

以下模式被視為問題

a { width: 100%; }
a { font-size: 10rem; }
a { animation: animation-name 5s ease; }

以下模式不是被視為問題

a { font-size: 1.2em; }
a { line-height: 1.2; }
a { height: 100px; }
a { height: 100PX; }
a { transform: rotate(30deg); }

可選次要選項

ignoreProperties: { "unit": ["property", "/regex/", /regex/]|"property"|"/regex/"|/regex/ }

忽略具有指定屬性的宣告值中的單位。

例如,使用 ["px", "em"]

給定

{
"rem": ["line-height", "/^border/"],
"%": ["width"]
}

以下模式不是被視為問題

a { line-height: 0.1rem; }
a { border-bottom-width: 6rem; }
a { width: 100%; }

以下模式被視為問題

a { margin: 0 20rem; }
a { -moz-border-radius-topright: 20rem; }
a { height: 100%; }

ignoreFunctions: ["function", "/regex/", /regex/]|"function"|"/regex/"|/regex/

忽略指定函式內部的單位。

例如,使用 ["px", "em"]

給定

["/^hsl/", "calc"]

以下模式不是被視為問題

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