freeCodeCamp/curriculum/challenges/chinese/01-responsive-web-design/basic-css/inherit-styles-from-the-bod...

1.7 KiB
Raw Blame History

id title challengeType videoUrl forumTopicId
bad87fee1348bd9aedf08746 从 Body 元素继承样式 0 https://scrimba.com/c/c9bmdtR 18204

--description--

我们已经证明每一个 HTML 页面都含有body元素,body元素也可以使用 CSS 样式。

设置body元素的样式的方式跟设置其他 HTML 元素的样式一样,并且其他元素也会继承到body设置的样式。

--instructions--

首先,创建一个文本内容为Hello Worldh1标签元素。

接着,在bodyCSS 规则里面添加一句color: green;,改变页面其他元素的字体颜色为green绿色

最后,同样在bodyCSS 规则里面添加font-family: monospace;,设置其他元素字体为font-family: monospace;

--hints--

创建一个h1元素。

assert($('h1').length > 0);

h1元素的文本内容应该为Hello World

assert(
  $('h1').length > 0 &&
    $('h1')
      .text()
      .match(/hello world/i)
);

确保h1元素具有结束标记。

assert(
  code.match(/<\/h1>/g) &&
    code.match(/<h1/g) &&
    code.match(/<\/h1>/g).length === code.match(/<h1/g).length
);

body元素的color属性值应为green

assert($('body').css('color') === 'rgb(0, 128, 0)');

body元素的font-family属性值应为monospace

assert(
  $('body')
    .css('font-family')
    .match(/monospace/i)
);

h1元素应该继承bodymonospace字体属性。

assert(
  $('h1').length > 0 &&
    $('h1')
      .css('font-family')
      .match(/monospace/i)
);

h1元素的字体颜色也应该继承body元素的绿色。

assert($('h1').length > 0 && $('h1').css('color') === 'rgb(0, 128, 0)');

--solutions--