forced-colors
CSS
media feature
is used to detect if the
用户代理
has enabled a forced colors mode where it enforces a user-chosen limited color palette on the page.
注意: This feature is not supported by any user agent and its specifics are subject to change.
forced-colors
media feature indicates whether or not the browser is currently in forced-colors mode.
none
Forced colors mode is not active; the page’s colors are not being forced into a limited palette.
active
prefers-color-scheme
so that authors can adapt the page.
In forced colors mode, the values of the following properties are treated as if they have no author-level values specified. That is, user-specified values (if any) or browser-specified values are used instead.
color
fill
stroke
text-decoration-color
text-emphasis-color
border-color
outline-color
column-rule-color
scrollbar-color
-webkit-tap-highlight-color
box-shadow
text-shadow
可以使用 system color keywords with any property other than those listed above, to ensure that the rest of the page integrates with the restricted color palette available in forced colors mode.
Currently no user agent implements this feature, although various operating systems do support such preferences and if this media query is ever implemented user agents will likely rely on the settings provided by the operating system in use.
注意: No browser currently implements this feature so the following example will not work.
This example has an annoying color palette by default. This example does not take advantage of the colors provided by the user agent.
<div class="colors">weird color box</div>
.colors {
background-color: red;
color: grey;
}
@media (forced-colors: active) {
.colors {
background-color: white;
color: black;
}
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
Media Queries Level 5
The definition of 'forced-colors' 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 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
forced-colors
media feature
Experimental
|
Chrome
完整支持
79
注意事项
Disabled
|
Edge 完整支持 79 |
Firefox
完整支持
81
Disabled
|
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
注意事项
|
完整支持
不支持
实验。期望将来行为有所改变。
见实现注意事项。
用户必须明确启用此特征。