Why does HTML think “chucknorris” is a color?

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

    chucknorris starts with c, and the browser reads it into a hexadecimal value.

    Because A, B, C, D, E, and F are characters in hexadecimal.

    The browser converts chucknorris to a hexadecimal value, C00C00000000.

    Then the C00C00000000 hexadecimal value is converted to RGB format (divided by 3):

    C00C00000000 ⇒ R:C00C, G:0000, B:0000

    The browser needs only two digits to indicate the colour:

    R:C00C, G:0000, B:0000 ⇒ R:C0, G:00, B:00 ⇒ C00000

    Finally, show bgcolor = C00000 in the web browser.

    Here's an example demonstrating it:

    chucknorris c00c00000000 c00000

提交回复
热议问题