2021-06-15 16:21:20 +02:00
---
id: 58c383d33e2e3259241f3076
2021-06-28 20:01:36 +05:30
title: Usar seletores de atributo para estilizar elementos
2021-06-15 16:21:20 +02:00
challengeType: 0
videoUrl: 'https://scrimba.com/c/cnpymfJ'
forumTopicId: 301092
dashedName: use-attribute-selectors-to-style-elements
---
# --description--
2021-06-28 20:01:36 +05:30
Você tem adicionado atributos de `id` ou `class` aos elementos que você deseja especificamente estilizar. Eles são conhecidos como ID e seletores de classe. Existem outros seletores CSS que você pode usar para selecionar grupos de elementos para estilizar.
2021-06-15 16:21:20 +02:00
2021-06-28 20:01:36 +05:30
Vamos usar o CatPhotoApp novamente para praticar o uso de seletores CSS.
2021-06-15 16:21:20 +02:00
2021-06-28 20:01:36 +05:30
Para este desafio, você usará o seletor de atributo `[attr=value]` para estilizar as caixas de seleção (checkboxes) no CatPhotoApp. Este seletor busca e estiliza elementos que possuam um atributo e valor específico. Por exemplo, o código abaixo altera as margens de todos os elementos com o atributo `type` que possua o valor `radio` :
2021-06-15 16:21:20 +02:00
```css
[type='radio'] {
margin: 20px 0px 20px 0px;
}
```
# --instructions--
2021-06-28 20:01:36 +05:30
Selecione todo elemento que possua o atributo `type` e tente dar às caixas de seleção no CatPhotoApp uma margem superior de 10px e uma margem inferior de 15px.
2021-06-15 16:21:20 +02:00
# --hints--
2021-06-28 20:01:36 +05:30
Você deve selecionar as caixas de seleção (checkboxes) usando o seletor de atributo do tipo `type` .
2021-06-15 16:21:20 +02:00
```js
assert(
code.match(
/< style > [ \s\S]*? \[\s*?type \s*?= \s*?("|')checkbox \1\s*? \]\s*?{[ \s\S]*?}[ \s\S]*?< \/style>/gi
)
);
```
2021-06-28 20:01:36 +05:30
As margens superiores das caixas de seleção devem ter 10px.
2021-06-15 16:21:20 +02:00
```js
assert(
(function () {
var count = 0;
$("[type='checkbox']").each(function () {
if ($(this).css('marginTop') === '10px') {
count++;
}
});
return count === 3;
})()
);
```
2021-06-28 20:01:36 +05:30
As margens inferiores das caixas de seleção devem ter 15px.
2021-06-15 16:21:20 +02:00
```js
assert(
(function () {
var count = 0;
$("[type='checkbox']").each(function () {
if ($(this).css('marginBottom') === '15px') {
count++;
}
});
return count === 3;
})()
);
```
# --seed--
## --seed-contents--
```html
< link href = "https://fonts.googleapis.com/css?family=Lobster" rel = "stylesheet" type = "text/css" >
< style >
.red-text {
color: red;
}
h2 {
font-family: Lobster, monospace;
}
p {
font-size: 16px;
font-family: monospace;
}
.thick-green-border {
border-color: green;
border-width: 10px;
border-style: solid;
border-radius: 50%;
}
.smaller-image {
width: 100px;
}
.silver-background {
background-color: silver;
}
< / style >
< h2 class = "red-text" > CatPhotoApp< / h2 >
< main >
< p class = "red-text" > Click here to view more < a href = "#" > cat photos< / a > .< / p >
2021-09-22 08:34:59 -07:00
< a href = "#" > < img class = "smaller-image thick-green-border" src = "https://cdn.freecodecamp.org/curriculum/cat-photo-app/relaxing-cat.jpg" alt = "A cute orange cat lying on its back." > < / a >
2021-06-15 16:21:20 +02:00
< div class = "silver-background" >
< p > Things cats love:< / p >
< ul >
< li > cat nip< / li >
< li > laser pointers< / li >
< li > lasagna< / li >
< / ul >
< p > Top 3 things cats hate:< / p >
< ol >
< li > flea treatment< / li >
< li > thunder< / li >
< li > other cats< / li >
< / ol >
< / div >
< form action = "https://freecatphotoapp.com/submit-cat-photo" id = "cat-photo-form" >
< label > < input type = "radio" name = "indoor-outdoor" checked > Indoor< / label >
< label > < input type = "radio" name = "indoor-outdoor" > Outdoor< / label > < br >
< label > < input type = "checkbox" name = "personality" checked > Loving< / label >
< label > < input type = "checkbox" name = "personality" > Lazy< / label >
< label > < input type = "checkbox" name = "personality" > Energetic< / label > < br >
< input type = "text" placeholder = "cat photo URL" required >
< button type = "submit" > Submit< / button >
< / form >
< / main >
```
# --solutions--
```html
< link href = "https://fonts.googleapis.com/css?family=Lobster" rel = "stylesheet" type = "text/css" >
< style >
.red-text {
color: red;
}
h2 {
font-family: Lobster, monospace;
}
p {
font-size: 16px;
font-family: monospace;
}
.thick-green-border {
border-color: green;
border-width: 10px;
border-style: solid;
border-radius: 50%;
}
.smaller-image {
width: 100px;
}
.silver-background {
background-color: silver;
}
[type='checkbox'] {
margin-top: 10px;
margin-bottom: 15px;
}
< / style >
< h2 class = "red-text" > CatPhotoApp< / h2 >
< main >
< p class = "red-text" > Click here to view more < a href = "#" > cat photos< / a > .< / p >
2021-06-28 20:01:36 +05:30
2021-09-22 08:34:59 -07:00
< a href = "#" > < img class = "smaller-image thick-green-border" src = "https://cdn.freecodecamp.org/curriculum/cat-photo-app/relaxing-cat.jpg" alt = "A cute orange cat lying on its back." > < / a >
2021-06-28 20:01:36 +05:30
2021-06-15 16:21:20 +02:00
< div class = "silver-background" >
< p > Things cats love:< / p >
< ul >
< li > cat nip< / li >
< li > laser pointers< / li >
< li > lasagna< / li >
< / ul >
< p > Top 3 things cats hate:< / p >
< ol >
< li > flea treatment< / li >
< li > thunder< / li >
< li > other cats< / li >
< / ol >
< / div >
2021-06-28 20:01:36 +05:30
2021-06-15 16:21:20 +02:00
< form action = "https://freecatphotoapp.com/submit-cat-photo" id = "cat-photo-form" >
< label > < input type = "radio" name = "indoor-outdoor" checked > Indoor< / label >
< label > < input type = "radio" name = "indoor-outdoor" > Outdoor< / label > < br >
< label > < input type = "checkbox" name = "personality" checked > Loving< / label >
< label > < input type = "checkbox" name = "personality" > Lazy< / label >
< label > < input type = "checkbox" name = "personality" > Energetic< / label > < br >
< input type = "text" placeholder = "cat photo URL" required >
< button type = "submit" > Submit< / button >
< / form >
< / main >
```