标签云

微信群

扫码加入我们

WeChat QR Code

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?


As a side note: don't use bgcolor. Use CSS background.

2019年06月26日43分54秒

Why do you ever want to add a background color called chucknorris? What was the expected color?

2019年06月26日43分54秒

masterFly: I don't know why my comment under the accepted answer was deleted for being "not constructive", because it answers your question quite well: people experiment with these things all the time. I was only 10 when I discovered this and all I was doing at the time was messing around and seeing what happened. You don't always have to have a practical reason for doing something, especially something as frivolous as this.

2019年06月26日43分54秒

and <body bgcolor="stevensegal"> test </body> is green

2019年06月26日43分54秒

Note that, despite what that blog post says, when you get to handling 3-char strings, you duplicate each character, rather than prepending 0.i.e. 0F6 becomes #00FF66, not #000F06.

2019年06月26日43分54秒

usr: HTML is built around intentionally ignoring malformed input ;)

2019年06月26日43分54秒

You can also use my random string to css color converter to get the color for a specific string. It's based on the 5 steps to calculate the string color by Jeremy Goodell.

2019年06月26日43分54秒

A hidden opportunity for semantics? You could make some error pages with this: <body bgcolor=error><h1 style=text-align:center>Error: Not Found<h1></span> You could add a div with anothe background or something like that, so it is not that aesthetically shocking.

2019年06月26日43分54秒

Theraot bgcolor="success" is a nice green, too.Interestingly, one can override these colours using CSS attribute/value selectors (e.g., td[bgcolor="chucknorris"] {...}).

2019年06月26日43分54秒

I figured it out, I had misinterpreted some of the parsing instructions: "adamlevine" = "ada00e000e" = "ada00e000e00" = "ada0 0e00 0e00" = "ad 0e 0e" -- Perfect!!

2019年06月26日43分54秒

In case you're interested, I posted the 5-step algorithm as an UPDATE on a similar question I posted today: stackoverflow.com/questions/12939234/…

2019年06月26日43分54秒

TimPietrusky created this freaking incredible demo tool for random color names. Just go here: randomstringtocsscolor.com and click in the box and type "chucknorris".

2019年06月26日43分54秒

adamlevine does work as per jsfiddle.net/LdyZ8/2959 but the letters are blocked into ada00e000e which is padded to ada00e000e00 but then reduced down to the typical HEX 6 digit value of [ad]a0[0e]00[0e]00 thus making ad0e0e which appears in the jsfiddle above.

2019年06月25日43分54秒

It would be better if this answer only contained the current state - the history of this answer and other answers belongs in the edit summaries and/or comments.

2019年06月26日43分54秒

Though I'm still curious as to why OP said "in CSS" and not "in HTML" - Maybe they're using a super old browser, or just mistaken?

2019年06月26日43分54秒

So then he is more than likely using the deprecated bgcolor attribute.

2019年06月26日43分54秒

Invalid characters are not skipped, they are treated as 0.

2019年06月26日43分54秒

(WHile this answer may be dead) suggestion: Use background color instead to demonstrate teh colors. Text color is over such a small relative area it is hard to see differences or similarities

2019年06月26日43分54秒

This is so cute explanation :D :D :D

2019年06月26日43分54秒

That is some very old-school markup.

2019年06月26日43分54秒