* feat(tools): add seed/solution restore script * chore(curriculum): remove empty sections' markers * chore(curriculum): add seed + solution to Chinese * chore: remove old formatter * fix: update getChallenges parse translated challenges separately, without reference to the source * chore(curriculum): add dashedName to English * chore(curriculum): add dashedName to Chinese * refactor: remove unused challenge property 'name' * fix: relax dashedName requirement * fix: stray tag Remove stray `pre` tag from challenge file. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
93 lines
2.0 KiB
Markdown
93 lines
2.0 KiB
Markdown
---
|
||
id: bad87fee1348bd9aedf04756
|
||
title: Class 选择器的优先级高于继承样式
|
||
challengeType: 0
|
||
videoUrl: 'https://scrimba.com/c/cGJDQug'
|
||
forumTopicId: 18253
|
||
dashedName: override-styles-in-subsequent-css
|
||
---
|
||
|
||
# --description--
|
||
|
||
"pink-text" class 覆盖了 `body` 元素的 CSS 声明。
|
||
|
||
我们刚刚证明了我们的 class 会覆盖 `body` 的 CSS 样式。那么下一个问题是,我们要怎么样才能覆盖我们的 `pink-text` class 中所定义的样式?
|
||
|
||
# --instructions--
|
||
|
||
创建一个字体颜色为 `blue` 的 `blue-text` class,并确保它在 `pink-text` 下方声明。
|
||
|
||
在含有 `pink-text` class 的 `h1` 元素里面,添加上 `blue-text` class。我们来看看到底是谁获胜。
|
||
|
||
HTML 同时应用多个 class 属性需以空格来间隔,例子如下:
|
||
|
||
`class="class1 class2"`
|
||
|
||
**注意:**HTML 元素里应用的 class 的先后顺序无关紧要。
|
||
|
||
但是,在 `<style>` 标签里面声明的 `class` 顺序十分重要,之后的声明会覆盖之前的声明。由于 `.blue-text` 在 `.pink-text` 的后面出现,所以 `.blue-text` 里的样式会覆盖 `.pink-text` 里的样式。
|
||
|
||
# --hints--
|
||
|
||
`h1` 元素应包含 `pink-text` class。
|
||
|
||
```js
|
||
assert($('h1').hasClass('pink-text'));
|
||
```
|
||
|
||
`h1` 元素应包含 `blue-text` class。
|
||
|
||
```js
|
||
assert($('h1').hasClass('blue-text'));
|
||
```
|
||
|
||
`blue-text` 和 `pink-text` 需同时应用于 `h1` 元素上。
|
||
|
||
```js
|
||
assert($('.pink-text').hasClass('blue-text'));
|
||
```
|
||
|
||
`h1` 元素的颜色应为蓝色。
|
||
|
||
```js
|
||
assert($('h1').css('color') === 'rgb(0, 0, 255)');
|
||
```
|
||
|
||
# --seed--
|
||
|
||
## --seed-contents--
|
||
|
||
```html
|
||
<style>
|
||
body {
|
||
background-color: black;
|
||
font-family: monospace;
|
||
color: green;
|
||
}
|
||
.pink-text {
|
||
color: pink;
|
||
}
|
||
</style>
|
||
<h1 class="pink-text">Hello World!</h1>
|
||
```
|
||
|
||
# --solutions--
|
||
|
||
```html
|
||
<style>
|
||
body {
|
||
background-color: black;
|
||
font-family: monospace;
|
||
color: green;
|
||
}
|
||
.pink-text {
|
||
color: pink;
|
||
}
|
||
|
||
.blue-text {
|
||
color: blue;
|
||
}
|
||
</style>
|
||
<h1 class="pink-text blue-text">Hello World!</h1>
|
||
```
|