Why does HTML think “chucknorris” is a color?

后端 未结 9 2064
醉梦人生
醉梦人生 2020-11-22 05:07

How come certain random strings produce colors when entered as background colors in HTML? For example:

9条回答
  •  甜味超标
    2020-11-22 05:43

    I'm sorry to disagree, but according to the rules for parsing a legacy color value posted by @Yuhong Bao, chucknorris DOES NOT equate to #CC0000, but rather to #C00000, a very similar but slightly different hue of red. I used the Firefox ColorZilla add-on to verify this.

    The rules state:

    • make the string a length that is a multiple of 3 by adding 0s: chucknorris0
    • separate the string into 3 equal length strings: chuc knor ris0
    • truncate each string to 2 characters: ch kn ri
    • keep the hex values, and add 0's where necessary: C0 00 00

    I was able to use these rules to correctly interpret the following strings:

    • LuckyCharms
    • Luck
    • LuckBeALady
    • LuckBeALadyTonight
    • GangnamStyle

    UPDATE: The original answerers who said the color was #CC0000 have since edited their answers to include the correction.

提交回复
热议问题