freeCodeCamp/curriculum/challenges/chinese/01-responsive-web-design/basic-css/use-abbreviated-hex-code.md

3.1 KiB
Raw Blame History

id title challengeType videoUrl forumTopicId dashedName
bad87fee1348bd9aedf08719 使用缩写的十六进制编码 0 https://scrimba.com/c/cRkpKAm 18338 use-abbreviated-hex-code

--description--

许多人对超过 1600 万种颜色感到不知所措, 并且很难记住十六进制编码。 幸运的是,你可以使用缩写形式。

例如,红色的 #FF0000 十六进制编码可以缩写成 #F00。 在这种缩写形式里三个数字分别代表着红R、绿G、蓝B三原色。

这样,颜色的数量减少到了大约 4000 种。 且在浏览器里 #FF0000#F00 是完全相同的颜色。

--instructions--

接下来,使用缩写的十六进制编码给元素设置正确的颜色。

颜色十六进制编码缩写形式
蓝绿色#0FF
绿色#0F0
红色#F00
紫红色#F0F

--hints--

文本内容为 I am red!h1 元素的字体颜色 color 应该为红色。

assert($('.red-text').css('color') === 'rgb(255, 0, 0)');

应使用红色的 hex code 缩写形式,不应使用 #FF0000

assert(code.match(/\.red-text\s*?{\s*?color\s*:\s*?#F00\s*?;?\s*?}/gi));

文本内容为 I am green!h1 元素的字体颜色 color 应该为绿色。

assert($('.green-text').css('color') === 'rgb(0, 255, 0)');

应使用绿色的 hex code 缩写形式,不应使用 #00FF00

assert(code.match(/\.green-text\s*?{\s*?color\s*:\s*?#0F0\s*?;?\s*?}/gi));

文本内容为 I am cyan!h1 元素的字体颜色 color 应该为蓝绿色。

assert($('.cyan-text').css('color') === 'rgb(0, 255, 255)');

应使用蓝绿色的 hex code 缩写形式,不应使用 #00FFFF

assert(code.match(/\.cyan-text\s*?{\s*?color\s*:\s*?#0FF\s*?;?\s*?}/gi));

文本内容为 I am fuchsia!h1 元素的字体颜色 color 应该为紫红色。

assert($('.fuchsia-text').css('color') === 'rgb(255, 0, 255)');

应使用紫红色的 hex code 缩写形式,不应使用 #FF00FF

assert(code.match(/\.fuchsia-text\s*?{\s*?color\s*:\s*?#F0F\s*?;?\s*?}/gi));

--seed--

--seed-contents--

<style>
  .red-text {
    color: #000000;
  }
  .fuchsia-text {
    color: #000000;
  }
  .cyan-text {
    color: #000000;
  }
  .green-text {
    color: #000000;
  }
</style>

<h1 class="red-text">I am red!</h1>

<h1 class="fuchsia-text">I am fuchsia!</h1>

<h1 class="cyan-text">I am cyan!</h1>

<h1 class="green-text">I am green!</h1>

--solutions--

<style>
  .red-text {
    color: #F00;
  }
  .fuchsia-text {
    color: #F0F;
  }
  .cyan-text {
    color: #0FF;
  }
  .green-text {
    color: #0F0;
  }
</style>

<h1 class="red-text">I am red!</h1>

<h1 class="fuchsia-text">I am fuchsia!</h1>

<h1 class="cyan-text">I am cyan!</h1>

<h1 class="green-text">I am green!</h1>