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

81 lines
1.9 KiB
Markdown
Raw Normal View History

---
id: bad87fee1348bd9aedf06756
challengeType: 0
videoUrl: 'https://scrimba.com/c/cGJDRha'
forumTopicId: 18252
2020-10-01 15:54:21 +00:00
title: 内联样式的优先级高于 ID 选择器
---
## Description
<section id='description'>
我们刚刚证明了id 选择器无论在<code>style</code>标签哪里声明,都会覆盖 class 声明的样式,
其实还有其他方法可以覆盖重写 CSS 样式。你还记得行内样式吗?
</section>
## Instructions
<section id='instructions'>
使用行内样式尝试让<code>h1</code>的字体颜色变白。像下面这样使用:
<code>&#60;h1 style="color: green"&#62;</code>
2020-01-08 04:40:17 +00:00
<code>h1</code>元素需继续保留<code>blue-text</code><code>pink-text</code>class。
</section>
## Tests
<section id='tests'>
```yml
tests:
- text: '<code>h1</code>元素应该包含<code>pink-text</code> class。'
2020-01-08 04:40:17 +00:00
testString: assert($("h1").hasClass("pink-text"));
- text: '<code>h1</code>元素应该包含<code>blue-text</code> class。'
2020-01-08 04:40:17 +00:00
testString: assert($("h1").hasClass("blue-text"));
- text: '<code>h1</code>元素应该包含一个名为<code>orange-text</code>的id。'
2020-01-08 04:40:17 +00:00
testString: assert($("h1").attr("id") === "orange-text");
- text: '<code>h1</code>元素应该含有行内样式。'
2020-01-08 04:40:17 +00:00
testString: assert(document.querySelector('h1[style]'));
- text: '<code>h1</code>元素的字体颜色应该为白色。'
2020-01-08 04:40:17 +00:00
testString: assert($("h1").css("color") === "rgb(255, 255, 255)");
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='html-seed'>
```html
<style>
body {
background-color: black;
font-family: monospace;
color: green;
}
#orange-text {
color: orange;
}
.pink-text {
color: pink;
}
.blue-text {
color: blue;
}
</style>
<h1 id="orange-text" class="pink-text blue-text">Hello World!</h1>
```
</div>
</section>
## Solution
<section id='solution'>
```html
// solution required
```
</section>