1.8 KiB
1.8 KiB
id | title | challengeType | videoUrl | forumTopicId | dashedName |
---|---|---|---|---|---|
bad87fee1348bd9aedf06756 | 内联样式的优先级高于 ID 选择器 | 0 | https://scrimba.com/c/cGJDRha | 18252 | override-class-declarations-with-inline-styles |
--description--
我们刚刚证明了,id 选择器无论在 style
标签的任何位置声明,都会覆盖 class 声明的样式。
其实还有其他方法可以覆盖 CSS 样式。 你还记得行内样式吗?
--instructions--
使用行内样式尝试让 h1
的字体颜色变白。 像这样使用:
<h1 style="color: green;">
h1
元素需继续保留 blue-text
和 pink-text
这两个 class。
--hints--
h1
元素应包含 pink-text
class。
assert($('h1').hasClass('pink-text'));
h1
元素应包含 blue-text
class。
assert($('h1').hasClass('blue-text'));
h1
元素的 id 应为 orange-text
。
assert($('h1').attr('id') === 'orange-text');
h1
元素应含有行内样式。
assert(document.querySelector('h1[style]'));
h1
元素的字体颜色应该为白色。
assert($('h1').css('color') === 'rgb(255, 255, 255)');
--seed--
--seed-contents--
<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>
--solutions--
<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" style="color: white">Hello World!</h1>