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

3.0 KiB
Raw Blame History

id title challengeType videoUrl localeTitle
bad87fee1348bd9aedf08746 Inherit Styles from the Body Element 0 从Body元素继承样式

Description

现在我们已经证明每个HTML页面都有一个body元素,并且它的body元素也可以用CSS设置样式。记住你可以风格你body元素就像任何其他HTML元素和所有其他元素将继承你的body元素的样式。

Instructions

首先,创建一个h1与文本元素Hello World然后,让我们给您的网页上的所有元素的颜色green中加入color: green;你的body元素的风格声明。最后,通过添加font-family: monospace; ,为你的body元素提供monospacefont-family: monospace;你的body元素的风格声明。

Tests

tests:
  - text: 创建一个<code>h1</code>元素。
    testString: 'assert(($("h1").length > 0), "Create an <code>h1</code> element.");'
  - text: 你的<code>h1</code>元素应该有文本<code>Hello World</code> 。
    testString: 'assert(($("h1").length > 0 && $("h1").text().match(/hello world/i)), "Your <code>h1</code> element should have the text <code>Hello World</code>.");'
  - text: 确保您的<code>h1</code>元素具有结束标记。
    testString: 'assert(code.match(/<\/h1>/g) && code.match(/<h1/g) && code.match(/<\/h1>/g).length === code.match(/<h1/g).length, "Make sure your <code>h1</code> element has a closing tag.");'
  - text: 为你的<code>body</code>元素赋予<code>green</code>的<code>color</code>属性。
    testString: 'assert(($("body").css("color") === "rgb(0, 128, 0)"), "Give your <code>body</code> element the <code>color</code> property of <code>green</code>.");'
  - text: 为<code>body</code>元素提供<code>monospace</code>的<code>font-family</code>属性。
    testString: 'assert(($("body").css("font-family").match(/monospace/i)), "Give your <code>body</code> element the <code>font-family</code> property of <code>monospace</code>.");'
  - text: 你的<code>h1</code>元素应该从你的<code>body</code>元素继承font <code>monospace</code> 。
    testString: 'assert(($("h1").length > 0 && $("h1").css("font-family").match(/monospace/i)), "Your <code>h1</code> element should inherit the font <code>monospace</code> from your <code>body</code> element.");'
  - text: 您的<code>h1</code>元素应该从您的<code>body</code>元素继承绿色。
    testString: 'assert(($("h1").length > 0 && $("h1").css("color") === "rgb(0, 128, 0)"), "Your <code>h1</code> element should inherit the color green from your <code>body</code> element.");'

Challenge Seed

<style>
  body {
    background-color: black;
  }

</style>

Solution

// solution required