freeCodeCamp/curriculum/challenges/chinese/01-responsive-web-design/basic-css/override-class-declarations...

3.0 KiB
Raw Blame History

id title challengeType videoUrl localeTitle
bad87fee1348bd8aedf06756 Override Class Declarations by Styling ID Attributes 0 通过样式ID属性覆盖类声明

Description

我们刚刚证明了浏览器从上到下读取CSS。这意味着如果发生冲突浏览器将使用最后的CSS声明。但我们还没有完成。还有其他方法可以覆盖CSS。你还记得id属性吗让我们覆盖你的pink-textblue-text类,并通过给h1元素一个id然后设置那个id样式使你的h1元素变成橙色。

Instructions

为你的h1元素提供orange-textid属性。请记住id样式如下所示 <h1 id="orange-text">h1元素上保留blue-textpink-text类。在style元素中为您的orange-text id创建一个CSS声明。这是一个示例
brown-text {
颜色:棕色;
}
注意无论您是在粉红色文本类之上还是之下声明此CSS都无关紧要因为id属性始终优先。

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>h1</code>元素提供<code>orange-text</code>的id。
    testString: 'assert($("h1").attr("id") === "orange-text", "Give your <code>h1</code> element the id of <code>orange-text</code>.");'
  - text: 应该只有一个<code>h1</code>元素。
    testString: 'assert(($("h1").length === 1), "There should be only one <code>h1</code> element.");'
  - text: 为您的<code>orange-text</code> ID创建一个CSS声明
    testString: 'assert(code.match(/#orange-text\s*{/gi), "Create a CSS declaration for your <code>orange-text</code> id");'
  - text: 不要给你的<code>h1</code>任何<code>style</code>属性。
    testString: 'assert(!code.match(/<h1.*style.*>/gi), "Do not give your <code>h1</code> any <code>style</code> attributes.");'
  - text: 你的<code>h1</code>元素应该是橙色的。
    testString: 'assert($("h1").css("color") === "rgb(255, 165, 0)", "Your <code>h1</code> element should be orange.");'

Challenge Seed

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

Solution

// solution required