<dimension> CSS data type represents a <number> with a unit attached to it, for example 10px .

CSS uses dimensions to specify distances ( <length> ), durations ( <time> ), frequencies ( <frequency> ), resolutions ( <resolution> ), and other quantities.

句法

The syntax of <dimension> <number> immediately followed by a unit which is an identifier. Unit identifiers are case insensitive.

范例

Valid dimensions

12px      12 pixels
1rem      1 rem
1.2pt     1.2 points
2200ms    2200 milliseconds
5s        5 seconds
200hz     200 Hertz
200Hz     200 Hertz (values are case insensitive)
					

Invalid dimensions

12 px       The unit must come immediately after the number.
12"px"      Units are identifiers and therefore unquoted.
3sec        The seconds unit is abbreviated "s" not "sec".
					

规范

规范 状态 注释
CSS Values and Units Module Level 4
The definition of '<dimension>' in that specification.
编者草案 添加 cap , ic , lh , rlh , vi , vb
CSS Values and Units Module Level 3
The definition of '<dimension>' in that specification.
候选推荐 添加 ch , rem , vw , vw , vmin , vmax , Q
CSS Level 2 (Revision 1)
The definition of '<dimension>' in that specification.
推荐 Defined under Numbers and Length
CSS Level 1
The definition of '<dimension>' in that specification.
推荐 Initial definition under "length units"

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
<dimension> Chrome 完整支持 1 Edge 完整支持 12 Firefox 完整支持 1 IE 完整支持 5 Opera 完整支持 3.5 Safari 完整支持 1 WebView Android 完整支持 ≤37 Chrome Android 完整支持 18 Firefox Android 完整支持 4 Opera Android 完整支持 10.1 Safari iOS 完整支持 1 Samsung Internet Android 完整支持 1.0

图例

完整支持

完整支持

另请参阅

元数据

  • 最后修改: