总结
<数字> CSS 数据类型代表一个数字,可为整数或小数。它的语法扩展了<integer>的数据值。要表示一个小数则加上小数部分 -- “."后跟一或多为十进制数字--到任何<integer>数据值。像<integer>数据类型一样,<number>没有任何单位,并不是一个CSS尺寸。
插值
<number> CSS数据类型的值可以被插值,用于动画。这种情况下,它们的插值是浮点实数。插值的速度取决于动画的 timing function。
示例
合法值示例:
12 A raw <integer> is also a <number> 4.01 正非整 <数字> -456.8 负非整 <数字> 0.0 零 +0.0 带正号的零 -0.0 带符号的零(尽管奇怪,但合法) .60 点前的数字可以省略 10e3 科学计数法 -3.4e-2 科学计数法最复杂的情况
非法值示例:
12. 点后需有数字 +-12.2 只能有一个符号 12.1.1 只能有一个点
规范
| 规范 | 状态 | 注释 |
|---|---|---|
| CSS Values and Units Module Level 3 <number> |
Candidate Recommendation | 与CSS Level 2 (Revision 1)没有明显变化 |
| CSS Level 2 (Revision 1) <number> |
Recommendation | Explicitly defined |
| CSS Level 1 <number> |
Recommendation | Implicitly defined |
浏览器兼容性
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
|---|---|---|---|---|---|
| basic | 1.0 | 1.0 (1.0) | <=5.0 | yes | 1.0 (85) |
| Scientific notation | ? | 29 | 11 | ? | ? |
| Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|
| Basic support | yes | yes | yes | yes | yes |
参见
- CSS Reference index