* feat(tools): add seed/solution restore script * chore(curriculum): remove empty sections' markers * chore(curriculum): add seed + solution to Chinese * chore: remove old formatter * fix: update getChallenges parse translated challenges separately, without reference to the source * chore(curriculum): add dashedName to English * chore(curriculum): add dashedName to Chinese * refactor: remove unused challenge property 'name' * fix: relax dashedName requirement * fix: stray tag Remove stray `pre` tag from challenge file. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
75 lines
1.4 KiB
Markdown
75 lines
1.4 KiB
Markdown
---
|
|
id: 587d7fa7367417b2b2512bc6
|
|
title: 给元素添加内联样式
|
|
challengeType: 6
|
|
forumTopicId: 301475
|
|
dashedName: add-inline-styling-to-elements
|
|
---
|
|
|
|
# --description--
|
|
|
|
D3 可以使用 `style()` 方法为动态元素添加内联 CSS 样式表。
|
|
|
|
`style()` 方法以用逗号分隔的键值对作为参数。这里是一个将选中文本的颜色设为蓝色的例子:
|
|
|
|
`selection.style("color","blue");`
|
|
|
|
# --instructions--
|
|
|
|
在编辑器中添加 `style()` 方法,使所有显示的文本的 `font-family` 为 `verdana`。
|
|
|
|
# --hints--
|
|
|
|
你的 `h2` 元素的 `font-family` 应该为 verdana。
|
|
|
|
```js
|
|
assert($('h2').css('font-family') == 'verdana');
|
|
```
|
|
|
|
你应该使用 `style()` 方法。
|
|
|
|
```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>
|
|
```
|