--- 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


```