--- id: 58c383d33e2e3259241f3076 title: 使用属性选择器来设置元素的样式 challengeType: 0 videoUrl: 'https://scrimba.com/c/cnpymfJ' forumTopicId: 301092 dashedName: use-attribute-selectors-to-style-elements --- # --description-- 我们已经通过设置元素的 `id` 和 `class` 来显示想要的样式。 这就是 ID 选择器和 Class 选择器。 另外,也还有其他的 CSS 选择器可以让我们给特定的元素设置样式。 让我们再次通过猫咪图片项目来练习 CSS 选择器。 在这个挑战里,我们需要使用 `[attr=value]` 属性选择器来修改 CatPhotoApp 中复选框的样式。 这个选择器使用特定的属性值来匹配和设置元素样式。 例如,下面的代码会改变所有 `type` 为 `radio` 的元素的外边距。 ```css [type='radio'] { margin: 20px 0px 20px 0px; } ``` # --instructions-- 请使用 `type` 属性选择器,设置复选框的上外边距为 10px,下外边距为 15px。 # --hints-- 应使用 `type` 属性选择器来匹配复选框。 ```js assert( code.match( /

CatPhotoApp

Click here to view more cat photos.

A cute orange cat lying on its back.

Things cats love:

Top 3 things cats hate:

  1. flea treatment
  2. thunder
  3. other cats


``` # --solutions-- ```html

CatPhotoApp

Click here to view more cat photos.

A cute orange cat lying on its back.

Things cats love:

Top 3 things cats hate:

  1. flea treatment
  2. thunder
  3. other cats


```