简体   繁体   English

在svg元素中为text标签添加样式

[英]adding style for the text tag in svg elements

I have a graph dynamically created so the svg contains a part with the following code. 我有一个动态创建的图形,因此svg包含具有以下代码的部分。 bt im unable to give background-color to this class.. ive tried it dynamically with the attr() function, but it doesnt work that way.. is there anyway to specify the css like svg:text?? bt im无法给此类提供背景颜色。.ive使用attr()函数动态地尝试了它,但是那样行不通..无论如何,是否可以像svg:text这样指定css?

<text id="circleText_Persons-bruno-waterfield" font-size="14" class="circleText" font-family="Tahoma" text-anchor="middle" background-color="#000000" font-weight="900" display="block" x="-1.8714285714285717" y="28.711414285714287" fill-opacity="1" stroke-opacity="1" style="fill: #666666;">Bruno Waterfield</text>

dynamic creation of svg text 动态创建svg文本

      nodeEnter.append("svg:text") 
  .attr("id", function(d){  return "circleText_" + d.name})
      .attr("font-size", function(d){return 14;}) //returnNodeSize(d) / 2
      .attr("class",  function(d){return "circleText"}).attr("font-family", "Tahoma")
      .attr("text-anchor","middle")
      .attr("background-color","#000000")
      .attr("font-weight","900")
      //returnNodeSize(d)+returnNodeSize(d)/1.8;
       .text(function(d){ 

         return toTitleCase(d.name));

Put a rect of your chosen color behind the text element conforming to the bounding box of the text. 将所选颜色的rect放置在符合text边界框的text元素后面。 SVG text does not have a flow box with which to set the background color; SVG文本没有用于设置背景颜色的流框。 you have to make one. 你必须做一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM