--- id: bad87fee1348bd8aedf06756 title: Override Class Declarations by Styling ID Attributes challengeType: 0 videoUrl: 'https://scrimba.com/c/cRkpDhB' forumTopicId: 18251 localeTitle: ID 选择器优先级高于 Class 选择器 --- ## Description
我们刚刚证明了浏览器读取 CSS 是由上到下的。这就意味着,如果发生冲突,浏览器将会应用最后声明的样式。 不过我们还没结束,还有其他方法来覆盖 CSS 样式。你还记得 id 属性吗? 通过给h1元素添加 id 属性,来覆盖 class 属性定义的同名样式。
## Instructions
h1元素添加 id 属性,属性值为orange-text。设置方式如下: <h1 id="orange-text"> h1元素继续保留blue-textpink-textclass。 在style元素中创建名为orange-text的 id 选择器。例子如下: ```css #brown-text { color: brown; } ``` 注意:无论在pink-textclass 的上面或者下面声明,id 选择器的优先级总是会高于 class 选择器。
## Tests
```yml tests: - text: 'h1元素应该包含pink-text class。' testString: assert($("h1").hasClass("pink-text")); - text: 'h1元素应该包含blue-text class。' testString: assert($("h1").hasClass("blue-text")); - text: 'h1的 id 属性值为orange-text。' testString: assert($("h1").attr("id") === "orange-text"); - text: '应该只有一个h1元素。' testString: assert(($("h1").length === 1)); - text: '创建名为orange-text的 id 选择器。' testString: assert(code.match(/#orange-text\s*{/gi)); - text: '不要在h1元素里面使用style(行内样式)。' testString: assert(!code.match(//gi)); - text: 'h1元素的字体颜色应为橘色。' testString: assert($("h1").css("color") === "rgb(255, 165, 0)"); ```
## Challenge Seed
```html

Hello World!

```
## Solution
```html // solution required ```