--- id: bad87dee1348bd9aede07836 title: Use an id Attribute to Style an Element challengeType: 0 videoUrl: '' localeTitle: 使用id属性为元素设置样式 --- ## Description
关于id属性的一个很酷的事情是,像类一样,你可以使用CSS来设置它们的样式。但是, id不可重用,只应应用于一个元素。 id也具有比类更高的特异性(重要性),因此如果两者都应用于同一元素并且具有冲突的样式,则将应用id的样式。下面是一个示例,说明如何使用cat-photo-elementid属性获取cat-photo-element并为其指定绿色的背景颜色。在你的style元素中:
#cat-photo-element {
背景颜色:绿色;
}
请注意,在style元素中,您始终通过放置a来引用类.在他们的名字前面。你总是通过在他们的名字前放一个#来引用id。
## Instructions
尝试提供您的表单,该表单现在具有cat-photo-formid属性,绿色背景。
## Tests
```yml tests: - text: 为form元素添加cat-photo-form的id。 testString: 'assert($("form").attr("id") === "cat-photo-form", "Give your form element the id of cat-photo-form.");' - text: 您的form元素应具有绿色的background-color 。 testString: 'assert($("#cat-photo-form").css("background-color") === "rgb(0, 128, 0)", "Your form element should have the background-color of green.");' - text: 确保您的form元素具有id属性。 testString: 'assert(code.match(//gi) && code.match(//gi).length > 0, "Make sure your form element has an id attribute.");' - text: 不要为form任何classstyle属性。 testString: 'assert(!code.match(//gi) && !code.match(//gi), "Do not give your form any class or style attributes.");' ```
## Challenge Seed
```html

CatPhotoApp

Click here to view more cat photos.

A cute orange cat lying on its back.

Things cats love:

  • cat nip
  • laser pointers
  • lasagna

Top 3 things cats hate:

  1. flea treatment
  2. thunder
  3. other cats


```
## Solution
```js // solution required ```