color-adjust - CSS: Cascading Style Sheets 编辑
The color-adjust
CSS property sets what, if anything, the user agent may do to optimize the appearance of the element on the output device. By default, the browser is allowed to make any adjustments to the element's appearance it determines to be necessary and prudent given the type and capabilities of the output device.
Syntax
color-adjust: economy; color-adjust: exact;
The color-adjust
property's value must be one of the following keywords.
Values
economy
- The user agent is allowed to make adjustments to the element as it deems appropriate and prudent in order to optimize the output for the device it's being rendered for. For example, when printing, a browser might opt to leave out all background images and to adjust text colors to be sure the contrast is optimized for reading on white paper. This is the default.
exact
- The element's content has been specifically and carefully crafted to use colors, images, and styles in a thoughtful and/or important way, such that being altered by the browser might actually make things worse rather than better. The appearance of the content should not be changed except by the user's request. For example, a page might include a list of information with rows whose background colors alternate between white and a light grey. Removing the background color would decrease the legibility of the content.
Usage notes
There are a number of reasons a browser might wish to deviate from the specified appearance, such as:
- The content uses text and background colors that will be too similar on the output device for legibility purposes.
- If the output device is a printer, and to save ink, dark or extremely dense background images might be removed.
- When printing a page, the browser might want to replace light-colored text on a dark background with dark text on a white background.
Any options the user agent offers the user to allow them to control the use of color and images will take priority over the value of color-adjust
. In other words, there isn't any guarantee that color-adjust
will do anything. Not only can the user override the behavior, but each user agent is allowed to decide for itself how to handle color-adjust
in any given situation.
Formal definition
Initial value | economy |
---|---|
Applies to | all elements |
Inherited | yes |
Computed value | as specified |
Animation type | discrete |
Formal syntax
economy | exact
Examples
Preserving low contrast
In this example, a box is shown which uses a background-image
and a translucent linear-gradient()()
function atop a black background color to have a dark blue gradient behind medium red text. For whatever reason, this is the desired appearance in any rendering environment, including on paper, so we also use color-adjust: exact
to tell the browser not to make color or style adjustments to the box when rendering it.
CSS
.my-box {
background-color: black;
background-image: linear-gradient(rgba(0, 0, 180, 0.5), rgba(70, 140, 220, 0.5));
color: #900;
width: 15rem;
height: 6rem;
text-align: center;
font: 24px "Helvetica", sans-serif;
display: flex;
align-items: center;
justify-content: center;
color-adjust: exact;
}
HTML
<div class="my-box">
<p>Need more contrast!</p>
</div>
Result
Specifications
Specification | Status | Comment |
---|---|---|
CSS Color Adjustment Module Level 1 The definition of 'color-adjust' in that specification. | Editor's Draft | Initial definition. |
Browser compatibility
BCD tables only load in the browser
The compatibility table in 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
- Applying color to HTML elements using CSS
- Other color-related properties:
color
,background-color
,border-color
,outline-color
,text-decoration-color
,text-emphasis-color
,text-shadow
,caret-color
, andcolumn-rule-color
background-image
-webkit-print-color-adjust
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论