forced-colors - CSS: Cascading Style Sheets 编辑

The forced-colors CSS media feature is used to detect if the user agent has enabled a forced colors mode where it enforces a user-chosen limited color palette on the page.

Note: This feature is not supported by any user agent and its specifics are subject to change.

Syntax

The forced-colors media feature indicates whether or not the browser is currently in forced-colors mode.

Values

none
Forced colors mode is not active; the page’s colors are not being forced into a limited palette.
active
Indicates that forced colors mode is active. The browser provides the color palette to authors through the CSS system color keywords and, if appropriate, it triggers the appropriate value of prefers-color-scheme so that authors can adapt the page.

Usage notes

Properties affected by forced-color mode

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.

You can use 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.

User preferences

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.

Examples

Note: 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.

HTML

<div class="colors">weird color box</div>

CSS

.colors {
  background-color: red;
  color: grey;
}

@media (forced-colors: active) {
  .colors {
    background-color: white;
    color: black;
  }
}

Result

Specifications

SpecificationStatusComment
Media Queries Level 5
The definition of 'forced-colors' in that specification.
Editor's DraftInitial definition.

Browser compatibility

BCD tables only load in the browser

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.

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:83 次

字数:5965

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文