--- id: bad87dee1348bd9aede07836 title: Usare un attributo id per stilizzare un elemento challengeType: 0 videoUrl: 'https://scrimba.com/c/cakyZfL' forumTopicId: 18339 dashedName: use-an-id-attribute-to-style-an-element --- # --description-- Una cosa interessante sugli attributi `id` è che, come le classi, è possibile stilizzarli utilizzando CSS. Tuttavia, un `id` non è riutilizzabile e dovrebbe essere applicato solo a un elemento. Un `id` ha anche una alta specificità (importanza) rispetto a una classe, quindi se entrambi sono applicati allo stesso elemento e hanno stili in conflitto, vengono applicati gli stili dell'`id`. Ecco un esempio di come puoi prendere il tuo elemento con l'attributo `id` di `cat-photo-element` e dargli il colore di sfondo verde. Nel tuo elemento `style`: ```css #cat-photo-element { background-color: green; } ``` Nota che all'interno del tuo elemento `style`, fai sempre riferimento alle classi mettendo un `.` di fronte ai loro nomi. Fai sempre riferimento agli id mettendo un `#` di fronte ai loro nomi. # --instructions-- Prova a dare al tuo modulo, che ora ha l'attributo `id` di `cat-photo-form`, uno sfondo verde. # --hints-- Il tuo elemento `form` dovrebbe avere l'id di `cat-photo-form`. ```js assert($('form').attr('id') === 'cat-photo-form'); ``` L'elemento `form` dovrebbe avere un `background-color` verde. ```js assert($('#cat-photo-form').css('background-color') === 'rgb(0, 128, 0)'); ``` Il tuo elemento `form` dovrebbe avere un attributo `id`. ```js assert( code.match(//gi) && code.match(//gi).length > 0 ); ``` Non dovresti dare al tuo `form` alcun attributo `class` o `style`. ```js assert(!code.match(//gi) && !code.match(//gi)); ``` # --seed-- ## --seed-contents-- ```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


``` # --solutions-- ```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


```