1.6 KiB
1.6 KiB
id, title, challengeType, videoUrl, forumTopicId
id | title | challengeType | videoUrl | forumTopicId |
---|---|---|---|---|
bad87dee1348bd9aede07836 | 使用 id 属性来设定元素的样式 | 0 | https://scrimba.com/c/cakyZfL | 18339 |
--description--
通过id
属性,你可以做一些很酷的事情,例如,就像 class 一样,你可以使用 CSS 来设置他们的样式
可是,id
不可以重用,只应用于一个元素上。同时,在 CSS 里,id
的优先级要高于class
,如果一个元素同时应用了class
和id
,并设置样式有冲突,会优先应用id
的样式。
选择id
为cat-photo-element
的元素,并设置它的背景样式为green
,可以在style
标签里这样写:
#cat-photo-element {
background-color: green;
}
注意在style
标签里,声明 class 的时候必须在名字前插入.
符号。同样,在声明 id 的时候,也必须在名字前插入#
符号。
--instructions--
尝试给含有cat-photo-form
id属性的form
表单的背景颜色设置为green
。
--hints--
设置form
元素的 id 为cat-photo-form
。
assert($('form').attr('id') === 'cat-photo-form');
form
元素应该含有background-color
css 属性并且值为 green
。
assert($('#cat-photo-form').css('background-color') === 'rgb(0, 128, 0)');
确保form
元素含有id
属性。
assert(
code.match(/<form.*cat-photo-form.*>/gi) &&
code.match(/<form.*cat-photo-form.*>/gi).length > 0
);
不要在form
元素上添加其他class
属性或者style
行内样式。
assert(!code.match(/<form.*style.*>/gi) && !code.match(/<form.*class.*>/gi));