1.7 KiB
1.7 KiB
id | title | required | challengeType | videoUrl | localeTitle | |||
---|---|---|---|---|---|---|---|---|
587d7fa7367417b2b2512bc6 | Add Inline Styling to Elements |
|
6 | 向元素添加内联样式 |
Description
style()
方法在动态元素上添加内联CSS样式。 style()
方法将逗号分隔的键值对作为参数。这是一个将选择的文本颜色设置为蓝色的示例: selection.style("color","blue");
Instructions
style()
方法添加到编辑器中的代码中,使所有显示的文本都具有verdana
的font-family
。 Tests
tests:
- text: 你的<code>h2</code>元素应该有verdana的<code>font-family</code> 。
testString: 'assert($("h2").css("font-family") == "verdana", "Your <code>h2</code> elements should have a <code>font-family</code> of verdana.");'
- text: 您的代码应使用<code>style()</code>方法。
testString: 'assert(code.match(/\.style/g), "Your code should use the <code>style()</code> method.");'
Challenge Seed
<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>
Solution
// solution required