标签云

微信群

扫码加入我们

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.

2018年07月17日50分23秒

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

2018年07月17日50分23秒

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.

2018年07月18日50分23秒

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

2018年07月17日50分23秒

Great! I’ll start using this now. Every time I actually try to type red it auto completes to rebeccapurple. PS google it if you don’t know the story.

2018年07月17日50分23秒

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.

2018年07月17日50分23秒

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

2018年07月17日50分23秒

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.

2018年07月17日50分23秒

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.

2018年07月17日50分23秒

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

2018年07月17日50分23秒

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

2018年07月17日50分23秒

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/…

2018年07月17日50分23秒

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

2018年07月17日50分23秒

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.

2018年07月17日50分23秒

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.

2018年07月18日50分23秒

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?

2018年07月18日50分23秒

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

2018年07月18日50分23秒

Perhaps he will be so kind as to post this magical HTML that produces a Chuck Norris red across "all browsers and platforms."

2018年07月17日50分23秒

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

2018年07月17日50分23秒

(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

2018年07月17日50分23秒

Sounds like what bucky will say

2018年07月17日50分23秒