How is the bgcolor property being calculated?

colors, html

Solution

My first try on this was a little trial on error and while I found some interesting properties of the system, it wasn't quite enough to form an answer. Next, I turned my attention to the standard. The reason that I believed this to be in the standard was that I tested it on three different browsers and they actually all did the same thing. Using the standard I found out what happens:

- All characters that aren't hexadecimal are replaced by zeroes (so only zeroes, 1-9 and a-e remain)

- The string is zero padded at the end to be a multiple of three

- The string is then divided up in three equal parts, each representing a color

- If the resulting strings are longer than 8 characters, take the last 8 characters of each string

- As long as each of the strings starts with a zero, the first character is removed from each string (not happening for this particular string since it starts with `De`

- The first two characters are taken from each of those strings and converted to a number for use as one of the components of the color

This way you'll see you get `00FA00` for `Deine Mutter hat eine Farbe und die ist grün.`

The html5 standard describes the process more precisely and actually describes a couple more cases here: http://www.w3.org/TR/html5/common-microsyntaxes.html#colors under the "rules for parsing a legacy color value"

Problem

Possible Duplicate: Why does HTML think “chucknorris” is a color? How is the `bgcolor` property calculated? When i use the following html code... ``` <body bgcolor="#Deine Mutter hat eine Farbe und die ist grün."></body> ``` ...what I get is the following color. By the way: When I try to use it in CSS it won´t work and will apply the standard color: ``` body{ color: #IchwillGOLD; } ``` Why?

Original source

Related problems