2021-06-15 00:49:18 -07:00
---
id: 587d7fa7367417b2b2512bc6
2021-07-03 20:07:10 +05:30
title: Aggiungere stili in linea agli elementi
2021-06-15 00:49:18 -07:00
challengeType: 6
forumTopicId: 301475
dashedName: add-inline-styling-to-elements
---
# --description--
2021-07-03 20:07:10 +05:30
D3 consente di aggiungere stili CSS in linea sugli elementi dinamici con il metodo `style()` .
2021-06-15 00:49:18 -07:00
2021-07-03 20:07:10 +05:30
Il metodo `style()` prende come argomento una coppia chiave-valore separata da virgole. Ecco un esempio per impostare il colore del testo della selezione a blu:
2021-06-15 00:49:18 -07:00
```js
selection.style("color","blue");
```
# --instructions--
2021-07-03 20:07:10 +05:30
Aggiungi il metodo `style()` al codice nell'editor per fare in modo che tutto il testo visualizzato abbia una `font-family` `verdana` .
2021-06-15 00:49:18 -07:00
# --hints--
2021-07-03 20:07:10 +05:30
I tuoi elementi `h2` dovrebbero avere una `font-family` `verdana` .
2021-06-15 00:49:18 -07:00
```js
assert($('h2').css('font-family') == 'verdana');
```
2021-07-03 20:07:10 +05:30
Il tuo codice dovrebbe usare il metodo `style()` .
2021-06-15 00:49:18 -07:00
```js
assert(code.match(/\.style/g));
```
# --seed--
## --seed-contents--
```html
< body >
< script >
const dataset = [12, 31, 22, 17, 25, 18, 29, 14, 9];
d3.select("body").selectAll("h2")
.data(dataset)
.enter()
.append("h2")
.text((d) => (d + " USD"))
// Add your code below this line
// Add your code above this line
< / script >
< / body >
```
# --solutions--
```html
< body >
< script >
const dataset = [12, 31, 22, 17, 25, 18, 29, 14, 9];
d3.select("body").selectAll("h2")
.data(dataset)
.enter()
.append("h2")
.text((d) => (d + " USD"))
.style("font-family", "verdana")
< / script >
< / body >
```