2021-02-06 04:42:36 +00:00
---
id: 587d7fa7367417b2b2512bc6
2021-10-03 12:24:27 -07:00
title: Agrega elementos de estilización en línea
2021-02-06 04:42:36 +00:00
challengeType: 6
forumTopicId: 301475
dashedName: add-inline-styling-to-elements
---
# --description--
2021-10-03 12:24:27 -07:00
D3 te permite añadir estilos CSS en línea sobre elementos dinámicos con el método `style()` .
2021-02-06 04:42:36 +00:00
2021-10-03 12:24:27 -07:00
El método `style()` toma un par llave-valor separado por coma como argumento. Aquí hay un ejemplo para establecer el color de texto de la selección a azul:
2021-02-06 04:42:36 +00:00
2021-07-09 21:23:54 -07:00
```js
selection.style("color","blue");
```
2021-02-06 04:42:36 +00:00
# --instructions--
2021-10-03 12:24:27 -07:00
Agrega el método `style()` al código en el editor para hacer que todo el texto mostrado tenga como `font-family` la fuente `verdana` .
2021-02-06 04:42:36 +00:00
# --hints--
2021-10-03 12:24:27 -07:00
Tus elementos `h2` deben tener como `font-family` la fuente `verdana` .
2021-02-06 04:42:36 +00:00
```js
assert($('h2').css('font-family') == 'verdana');
```
2021-10-03 12:24:27 -07:00
Tu código debe utilizar el método `style()` .
2021-02-06 04:42:36 +00: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 >
```