freeCodeCamp/curriculum/challenges/chinese/01-responsive-web-design/basic-css/override-styles-in-subseque...

2.5 KiB
Raw Blame History

id title challengeType videoUrl localeTitle
bad87fee1348bd9aedf04756 Override Styles in Subsequent CSS 0 覆盖后续CSS中的样式

Description

我们的“粉红色文本”类覆盖了我们的body元素的CSS声明我们刚刚证明我们的类将覆盖body元素的CSS。所以下一个合乎逻辑的问题是我们可以做些什么来覆盖我们的pink-text类?

Instructions

创建一个名为blue-text的附加CSS类它为元素提供蓝色。确保它低于pink-text类声明。除了pink-text类之外,将blue-text类应用于h1元素让我们看看哪个获胜。将多个类属性应用于HTML元素是通过它们之间的空格完成的如下所示 class="class1 class2"注意HTML元素中列出的类的顺序无关紧要。但是 <style>部分中的class声明的顺序是重要的。第二个声明将始终优先于第一个声明。因为.blue-text被声明为第二个,所以它会覆盖.pink-text的属性

Tests

tests:
  - text: 您的<code>h1</code>元素应该具有<code>pink-text</code>类。
    testString: 'assert($("h1").hasClass("pink-text"), "Your <code>h1</code> element should have the class <code>pink-text</code>.");'
  - text: 你的<code>h1</code>元素应该有<code>blue-text</code> 。
    testString: 'assert($("h1").hasClass("blue-text"), "Your <code>h1</code> element should have the class <code>blue-text</code>.");'
  - text: <code>blue-text</code>和<code>pink-text</code>都应属于同一个<code>h1</code>元素。
    testString: 'assert($(".pink-text").hasClass("blue-text"), "Both <code>blue-text</code> and <code>pink-text</code> should belong to the same <code>h1</code> element.");'
  - text: 你的<code>h1</code>元素应该是蓝色的。
    testString: 'assert($("h1").css("color") === "rgb(0, 0, 255)", "Your <code>h1</code> element should be blue.");'

Challenge Seed

<style>
  body {
    background-color: black;
    font-family: monospace;
    color: green;
  }
  .pink-text {
    color: pink;
  }
</style>
<h1 class="pink-text">Hello World!</h1>

Solution

// solution required