Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
228 views
in Technique[技术] by (71.8m points)

html - How is the bgcolor property being calculated?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

  1. All characters that aren't hexadecimal are replaced by zeroes (so only zeroes, 1-9 and a-e remain)
  2. The string is zero padded at the end to be a multiple of three
  3. The string is then divided up in three equal parts, each representing a color
  4. If the resulting strings are longer than 8 characters, take the last 8 characters of each string
  5. 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
  6. 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"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...