2.5 KiB
2.5 KiB
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