aspect-ratio
CSS
property sets a
preferred aspect ratio
for the box, which will be used in the calculation of auto sizes and some other layout functions.
aspect-ratio: 1 / 1; /* Global values */ aspect-ratio: inherit; aspect-ratio: initial; aspect-ratio: unset;
<auto>
<ratio>
width
/
height
. Size calculations involving preferred aspect ratio work with the dimensions of the box specified by
box-sizing
.
| 初始值 |
auto
|
|---|---|
| 适用于 | all elements except inline boxes and internal ruby or table boxes |
| 继承 | no |
| 计算值 | 如指定 |
| 动画类型 | discrete |
auto | <ratio>
aspect-ratio: 1 / 1; aspect-ratio: 16 / 9;
Browsers have added an internal
aspect-ratio
property that applies to replaced elements and other related elements that accept
width
and
height
attributes. This appears in the browser's internal UA stylesheet.
In Firefox, the internal stylesheet rule looks like this:
img, input[type="image"], video, embed, iframe, marquee, object, table {
aspect-ratio: attr(width) / attr(height);
}
You can read more about this feature in Setting Height And Width On Images Is Important Again .
| 规范 | 状态 | 注释 |
|---|---|---|
|
CSS Box Sizing Module Level 4
The definition of 'aspect-ratio' in that specification. |
编者草案 | 初始定义 |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
aspect-ratio
Experimental
|
Chrome
部分支持
79
注意事项
|
Edge
部分支持
79
注意事项
|
Firefox
部分支持
71
注意事项
|
IE 不支持 No | Opera 不支持 No |
Safari
部分支持
14
注意事项
|
WebView Android
部分支持
79
注意事项
|
Chrome Android
部分支持
79
注意事项
|
Firefox Android 不支持 No | Opera Android 不支持 No |
Safari iOS
部分支持
14
注意事项
|
Samsung Internet Android
部分支持
12.0
注意事项
|
| Internal mapping of width and height Experimental | Chrome 完整支持 79 | Edge 完整支持 79 |
Firefox
完整支持
71
|
IE 不支持 No | Opera 不支持 No | Safari 完整支持 14 | WebView Android 完整支持 79 | Chrome Android 完整支持 79 | Firefox Android 不支持 No | Opera Android 不支持 No | Safari iOS 完整支持 14 | Samsung Internet Android 完整支持 12.0 |
完整支持
部分支持
不支持
实验。期望将来行为有所改变。
见实现注意事项。
用户必须明确启用此特征。