<time>

Baseline 已廣泛支援

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

<time> CSS 資料型別表示以秒或毫秒錶示的時間值。它用於 animationtransition 和相關屬性。

語法

<time> 資料型別由一個 <number> 後跟下面列出的其中一個單位組成。可選地,它前面可以帶一個 +- 符號。與所有尺寸一樣,單位字面量和數字之間沒有空格。

注意:儘管數字 0 在任何單位下都相同,但單位不能省略。換句話說,0 是無效的,不表示 0s0ms

單位

s

表示以秒為單位的時間。示例:0s1.5s-60s

ms

表示以毫秒為單位的時間。示例:0ms150.25ms-60000ms

注意:sms 之間的轉換遵循邏輯 1s = 1000ms

示例

有效時間

12s         Positive integer
-456ms      Negative integer
4.3ms       Non-integer
14mS        The unit is case-insensitive, although capital letters are not recommended.
+0s         Zero with a leading + and a unit
-0ms        Zero with a leading - and a unit

無效時間

0           Although unitless zero is allowed for <length>s, it's invalid for <time>s.
12.0        This is a <number>, not a <time>, because it's missing a unit.
7 ms        No space is allowed between the number and the unit.

規範

規範
CSS 值和單位模組第 4 級
# 時間

瀏覽器相容性

另見