<ratio> CSS data type , used for describing aspect ratios in media queries , denotes the proportion between two unitless values.

句法

In Media Queries Level 3, the <ratio> data type consisted of a strictly positive <integer> followed by a forward slash ('/', Unicode U+002F SOLIDUS ) and a second strictly positive <integer> . Spaces before and after the slash are optional. The first number represents the width, while the second represents the height.

In Media Queries Level 4, the <ratio> date type is updated to consist of a strictly positive <number> followed by a forward slash ('/', Unicode U+002F SOLIDUS ) and a second strictly positive <number> . In addition a single <number> as a value is allowable.

范例

Use in a media query

@media screen and (min-aspect-ratio: 16/9) { ... }
					

Common aspect ratios

Ratio 用法
Ratio4_3.png 4/3 Traditional TV format in the 20 th century.
Ratio16_9.png 16/9 Modern "widescreen" TV format.
Ratio1_1.85.png 185/100 = 91/50 The most common movie format since the 1960s.
Ratio1_2.39.png 239/100
"Widescreen," anamorphic movie format.

规范

规范 状态 注释
Media Queries Level 4
The definition of '<ratio>' in that specification.
候选推荐
Media Queries
The definition of '<ratio>' in that specification.
推荐 初始定义。

浏览器兼容性

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
<ratio> Chrome 完整支持 3 Edge 完整支持 12 Firefox 完整支持 3.5 IE 完整支持 9 Opera 完整支持 9.5 Safari 完整支持 5 WebView Android 完整支持 ≤37 Chrome Android 完整支持 18 Firefox Android 完整支持 4 Opera Android 完整支持 14 Safari iOS 完整支持 4.2 Samsung Internet Android 完整支持 1.0
Accepts <number> / <number> or single <number> as a value. Chrome 不支持 No Edge 不支持 No Firefox 完整支持 70 Disabled
完整支持 70 Disabled
Disabled ). To change preferences in Firefox, visit
IE 不支持 No Opera 不支持 No Safari 不支持 No WebView Android 不支持 No Chrome Android 不支持 No Firefox Android 不支持 No Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android 不支持 No

图例

完整支持

完整支持

不支持

不支持

用户必须明确启用此特征。

用户必须明确启用此特征。

另请参阅

元数据

  • 最后修改: