Css-PHP: Is there any way to determine whether a color value is close to white?

Source: Internet
Author: User
Requirement: if the background of some white text is close to White, the text cannot be clearly viewed. Therefore, you must set the text color to black for this background color. known invalid method: convert the color into a 10 hexadecimal value and cannot judge whether it is close to White {code ...} requirements:
If the background of some white text is close to White, the text cannot be clearly viewed. Therefore, you must set the text color to black for this background color.

Known invalid methods:

Converting the color to 10 decimal format cannot determine whether it is near White

Although the red value is 16711680, it can be distinguished from white, but the gray 12632256 is smaller than red, but it is difficult to distinguish from White.

Reply content:

Requirements:
If the background of some white text is close to White, the text cannot be clearly viewed. Therefore, you must set the text color to black for this background color.

Known invalid methods:

Converting the color to 10 decimal format cannot determine whether it is near White

Although the red value is 16711680, it can be distinguished from white, but the gray 12632256 is smaller than red, but it is difficult to distinguish from White.

Reversed. Smaller and brighter

You can use the RGB value to determine the color of an unclear font. if the color is greater than the RGB value, you can add an average value.

Convert each digit of rgb to decimal and 255 for comparison. for example, if the gap between each value and 255 is within 5, it is determined that it is very close to White, instead, the entire hexadecimal format cannot be directly converted to decimal.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.