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

CatPhotoApp

一只仰卧着的萌猫

猫咪最喜欢的三件东西:

  • 猫薄荷
  • 激光笔
  • 千层饼

猫咪最讨厌的三件东西:

  1. 跳蚤
  2. 打雷
  3. 同类


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