部分使工具提示文本加粗

时间:2021-04-08 14:53:41

标签: javascript d3.js tooltip

我正在尝试将工具提示中的第一行文本设为粗体。 下面的代码是我目前所拥有的,但它不起作用。

  tooltip.html("<b>" + smartData[yearSlider][d3.select(this).attr("country")]["country"] + "</b> <br>" +
  "Total CO2 Emission excluding LULUCF" + "<br>" + 
  smartData[yearSlider][d3.select(this).attr("country")]["totalghgexlulucf"] + 
  "<br>" + "Total CO2 Emission including LULUCF" + "<br>" +
  smartData[yearSlider][d3.select(this).attr("country")]["totalghginclulucf"] +
  "<br>")
  

下面的截图是上面代码的结果(一些 CSS 被用来设置工具提示的样式等)

Result of tooltip code

谁能帮我解决这个问题? 如果您需要更多代码来帮助我解决这个问题,我非常乐意与您分享! :)

对不起,我的英语不好,这不是我的母语。 提前致谢!

1 个答案:

答案 0 :(得分:1)

嗨,您可以通过使用带有类的跨度并在 css 文件中设置类的样式来解决此问题:

tooltip.html("<span class='tooltip-text-bold'>" + smartData[yearSlider][d3.select(this).attr("country")]["country"] + "</span> <br>" +
  "Total CO2 Emission excluding LULUCF" + "<br>" + 
  smartData[yearSlider][d3.select(this).attr("country")]["totalghgexlulucf"] + 
  "<br>" + "Total CO2 Emission including LULUCF" + "<br>" +
  smartData[yearSlider][d3.select(this).attr("country")]["totalghginclulucf"] +
  "<br>")

然后你在 css 中使用:

.tooltip-text-bold{
    font-weight: 700;
}
相关问题