+ 7
Why does HTML think “chucknorris” is a color?
How come certain random strings produce colors when entered as background colors in HTML? For example: ///////// <body bgcolor="chucknorris"> test </body> //////// ...produces a document with a red background across all browsers and platforms. Interestingly, while "chucknorri" produces a red background as well, "chucknorr" produces a yellow background. What's going on here? 😂
4 ответов
+ 25
While parsing colors, invalid digits are considered as 0. So,
chucknorris => c00c0000000
This is divided to 3 parts (r, g, b). So,
chucknorris => c00c 0000 000
Only the first two digits are considered. So,
chucknorris => c0 00 00
And, RGB(c0, 00, 00) is RED. I think you can get why chucknorr => yellow now.
+ 8
This only work with 'bgcolor' and other depecrated html attributes: this is not the behaviour for Css color declaration, which ignore invalid names... This is due to the permissivity of Html specifications which intend browsers to display invalid document as well as they can, by auto correcting invalid Html... So the value set to a deprecated styling attribute will be converted at parse time to a css style declaration and invalid values are also tried to be displaying as much as possible (Css specifications are not as much permissive for invalid values) ^^
+ 5
Because Chuck Norris, duh 😂
+ 1
Just stumbled across this. This is a very interesting feature of HTML...