HTML标签】为什么HTML认为 ldquo ChuckNorris rdquo 是一种颜色

2020-09-11 11:49发布

2条回答
我是大脸猫
2楼 · 2020-09-13 10:57

当在 HTML中作为背景颜色输入时,某些随机字符串如何产生颜色?例如:



 test 

…在所有浏览器和平台上生成一个红色背景的文档.

有趣的是,虽然chucknorri也产生红色背景,但chucknorr产生黄色背景.

这里发生了什么?

这是Netscape日子的延续:



Missing digits are treated as 0[…]. An incorrect digit is simply interpreted as 0. For example the values #F0F0F0, F0F0F0, F0F0F, #FxFxFx and FxFxFx are all the same.

它来自博客文章A little rant about Microsoft Internet Explorer’s color parsing,它详细介绍了它,包括不同长度的颜色值等.

如果我们依次从博客文章中应用规则,我们会得到以下信息:

>用0替换所有无效的十六进制字符


chucknorris becomes c00c0000000

>填写下一个可被3整除的字符总数(11 – > 12)


c00c 0000 0000

>分成三个相等的组,每个组件代表RGB颜色的相应颜色分量:


RGB (c00c, 0000, 0000)

>将每个参数从右向下截断为两个字符

这给出了以下结果:


RGB (c0, 00, 00) = #C00000 or RGB(192, 0, 0)

这是一个演示bgcolor属性的示例,用于生成这个“惊人”的色样:



  
    
    
    
  
  
    
    
    
  
chuck norrisMr Tninjaturtle
sickcrapgrass

这也回答了问题的其他部分;为什么bgcolor =“chucknorr”会产生黄色?好吧,如果我们应用规则,字符串是:


c00c00000 => c00 c00 000 => c0 c0 00 [RGB(192, 192, 0)]

这给出了淡黄色的金色.当字符串以9个字符开始时,我们这次保留第二个C因此它最终成为最终颜色值.

当有人指出你可以做color =“crap”时,我最初遇到了这个问题,而且,它出现了棕色.


乐xenia
3楼 · 2020-09-21 17:31

How come certain random strings produce colors when entered as background colors in HTML? For example:


 test 


...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?


相关问题推荐

没有解决我的问题,去提问