Why does HTML think “chucknorris” is a color?

后端 未结 9 2055
醉梦人生
醉梦人生 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:39

    Most browsers will simply ignore any NON-hex values in your color string, substituting non-hex digits with zeros.

    ChuCknorris translates to c00c0000000. At this point, the browser will divide the string into three equal sections, indicating Red, Green and Blue values: c00c 0000 0000. Extra bits in each section will be ignored, which makes the final result #c00000 which is a reddish color.

    Note, this does not apply to CSS color parsing, which follow the CSS standard.

    Redish

    Same as above

    Black

提交回复
热议问题