<integer>

Baseline 已廣泛支援

此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 ⁨2015 年 7 月⁩以來,各瀏覽器均已提供此特性。

<integer> CSS 資料型別是一種特殊的 <number> 型別,它表示一個正或負的整數。整數可以用於許多 CSS 屬性和描述符,例如 column-countcounter-incrementgrid-columngrid-rowz-index 屬性以及 range 描述符。

語法

<integer> 資料型別由一個或多個十進位制數字(0 到 9,包括 0 和 9)組成,前面可選帶一個 +- 號。整數沒有關聯的單位。

注意: <integer> 值沒有官方的有效範圍,規範也沒有指定範圍。

插值

在動畫中,<integer> 資料型別的值使用離散的整步進行插值。計算過程如同它們是實數、浮點數一樣;離散值透過向下取整函式獲得。插值的速度由與動畫關聯的緩動函式決定。

示例

有效整數

12          Positive integer (without a leading + sign)
+123        Positive integer (with a leading + sign)
-456        Negative integer
0           Zero
+0          Zero, with a leading +
-0          Zero, with a leading -

無效整數

12.0        This is a <number>, not an <integer>, though it represents an integer.
12.         Decimal points are not allowed.
+---12      Only one leading +/- is allowed.
ten         Letters are not allowed.
_5          Special characters are not allowed.
\35         Escaped Unicode characters are not allowed, even if they are an integer (here: 5).
\4E94       Non-arabic numerals are not allowed, even when escaped (here: the Japanese 5, 五).
3e4         Scientific notation is not allowed.

規範

規範
CSS 值和單位模組第 4 級
# 整數

瀏覽器相容性

另見