2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
id: bad87fee1348bd9aedf08756
|
|
|
|
|
title: Prioritize One Style Over Another
|
|
|
|
|
challengeType: 0
|
2019-12-13 13:47:57 +08:00
|
|
|
|
videoUrl: 'https://scrimba.com/c/cZ8wnHv'
|
|
|
|
|
forumTopicId: 18258
|
2020-01-08 12:40:17 +08:00
|
|
|
|
localeTitle: 样式中的优先级
|
2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## Description
|
2019-12-13 13:47:57 +08:00
|
|
|
|
<section id='description'>
|
2020-01-08 12:40:17 +08:00
|
|
|
|
有时候, HTML 元素的样式会跟其他样式发生冲突。
|
|
|
|
|
就像,<code>h1</code>元素也不能同时设置<code>green</code>和<code>pink</code>两种样式。
|
2019-12-13 13:47:57 +08:00
|
|
|
|
让我们尝试创建一个字体颜色为<code>pink</code>的 class,并应于用其中一个元素中。猜一猜,它会覆盖<code>body</code>元素设置的<code>color: green;</code>CSS 属性吗?
|
|
|
|
|
</section>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
## Instructions
|
2019-12-13 13:47:57 +08:00
|
|
|
|
<section id='instructions'>
|
|
|
|
|
创建一个能将元素的字体颜色改为<code>pink</code>的CSS class,并起名为<code>pink-text</code>。
|
2020-01-08 12:40:17 +08:00
|
|
|
|
给<code>h1</code>元素添加<code>pink-text</code>class。
|
2019-12-13 13:47:57 +08:00
|
|
|
|
</section>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
## Tests
|
|
|
|
|
<section id='tests'>
|
|
|
|
|
|
|
|
|
|
```yml
|
|
|
|
|
tests:
|
2019-12-13 13:47:57 +08:00
|
|
|
|
- text: '<code>h1</code>元素应该含有<code>pink-text</code> class。'
|
2020-01-08 12:40:17 +08:00
|
|
|
|
testString: assert($("h1").hasClass("pink-text"));
|
2019-12-13 13:47:57 +08:00
|
|
|
|
- text: '<code><style></code>标签应该含有一个可以改变字体颜色的<code>pink-text</code> class。'
|
2020-01-08 12:40:17 +08:00
|
|
|
|
testString: 'assert(code.match(/\.pink-text\s*\{\s*color\s*:\s*.+\s*;\s*\}/g));'
|
2019-12-13 13:47:57 +08:00
|
|
|
|
- text: '<code>h1</code>元素的字体颜色应该为<code>pink(粉色)</code>。'
|
2020-01-08 12:40:17 +08:00
|
|
|
|
testString: assert($("h1").css("color") === "rgb(255, 192, 203)");
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
## Challenge Seed
|
|
|
|
|
<section id='challengeSeed'>
|
|
|
|
|
|
|
|
|
|
<div id='html-seed'>
|
|
|
|
|
|
|
|
|
|
```html
|
|
|
|
|
<style>
|
|
|
|
|
body {
|
|
|
|
|
background-color: black;
|
|
|
|
|
font-family: monospace;
|
|
|
|
|
color: green;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
<h1>Hello World!</h1>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
## Solution
|
|
|
|
|
<section id='solution'>
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
// solution required
|
|
|
|
|
```
|
2019-12-13 13:47:57 +08:00
|
|
|
|
|
2018-10-10 18:03:03 -04:00
|
|
|
|
</section>
|
2019-12-13 13:47:57 +08:00
|
|
|
|
|