非标
此特征是非标准的,且不在标准轨道中。不要在面向 Web 的生产站点中使用它:它不适用于每个用户。实现之间可能存在大的不兼容性,且行为将来可能改变。
-webkit-device-pixel-ratio
is a non-standard Boolean
CSS
media feature
which is an alternative to the standard
resolution
media feature.
注意:
This media feature is a WebKit feature. If possible, use the
resolution
media feature query instead.
-webkit-device-pixel-ratio
feature is specified as a
<number>
value. It is a range feature, meaning that you can also use the prefixed
-webkit-min-device-pixel-ratio
and
-webkit-max-device-pixel-ratio
variants to query minimum and maximum values, respectively.
<number>
px
. Although the value is a
<number>
, and thus doesn't syntactically allow units, its implicit unit is
dppx
.
/* A unit of "dppx" is implied: */
@media (-webkit-min-device-pixel-ratio: 2) { ... }
/* ... is equivalent to: */
@media (min-resolution: 2dppx) { ... }
/* Similarly: */
@media (-webkit-max-device-pixel-ratio: 2) { ... }
/* ... is equivalent to: */
@media (max-resolution: 2dppx) { ... }
<p>This is a test of your device's pixel density.</p>
/* Exact resolution */
@media (-webkit-device-pixel-ratio: 1) {
p {
color: red;
}
}
/* Minimum resolution */
@media (-webkit-min-device-pixel-ratio: 1.1) {
p {
font-size: 1.5em;
}
}
/* Maximum resolution */
@media (-webkit-max-device-pixel-ratio: 3) {
p {
background: yellow;
}
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
Compatibility Standard
The definition of '-webkit-device-pixel-ratio' in that specification. |
实时标准 | Initial standardization |
|
Safari CSS Reference
'media query extensions' in that document. |
Non-standard unofficial documentation | Initial documentation |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
-webkit-device-pixel-ratio
media feature
非标
|
Chrome 完整支持 1 | Edge 完整支持 12 |
Firefox
完整支持
63
注意事项
|
IE 不支持 No | Opera 完整支持 15 | Safari 完整支持 3 | WebView Android 完整支持 ≤37 | Chrome Android 完整支持 18 |
Firefox Android
完整支持
63
注意事项
|
Opera Android 完整支持 14 | Safari iOS 完整支持 1 | Samsung Internet Android 完整支持 1.0 |
完整支持
不支持
非标。预期跨浏览器支持较差。
见实现注意事项。
用户必须明确启用此特征。
<resolution>
-webkit-transform-2d
-webkit-transform-3d
-webkit-transition
-webkit-animation