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