【问题标题】:SVG textpath issuesSVG 文本路径问题
【发布时间】:2015-11-19 10:02:07
【问题描述】:

我正在处理 SVG 元素,并且在路径上添加了一个文本路径。就像在这个链接上一样。

https://developer.mozilla.org/en/docs/Web/SVG/Element/textPath

但我需要在两行中添加文本,例如用“br”分隔。

有人知道怎么做吗? 最好的问候,

【问题讨论】:

  • 到目前为止你尝试过什么? Ps,如果你下次提供英文网址就好了,不是fr ..
  • 我可能不明白您真正想要什么,但您似乎想要创建 2 个单独的路径和 2 个 textPaths,对吗?我认为不可能沿多条路径分发textPath,尤其是当您想中断特定字符时,这需要逻辑,而不是标记。如果我错了,请纠正我。
  • @MatthijsvanHest 对不起,FR 中的链接,我添加了一个 img,以便您可以看到我需要做什么。
  • @MatthijsvanHest Somone 回答了这个问题,谢谢你的帮助:)
  • 我看到了。 :) 正如我所说:它需要有 2 个单独的 textPaths ;) 你不能在 <br> 或其他任何东西上打破它,谢谢你 LOL:P

标签: text svg


【解决方案1】:

以 em 为单位使用 dy:

<svg width="100%" height="100%" viewBox="0 0 1000 300"
     xmlns="http://www.w3.org/2000/svg" 
     xmlns:xlink="http://www.w3.org/1999/xlink">
  <defs>
    <path id="MyPath"
          d="M 100 200 
             C 200 100 300   0 400 100
             C 500 200 600 300 700 200
             C 800 100 900 100 900 100" />    
  </defs>

  <use xlink:href="#MyPath" fill="none" stroke="red"  />

  <text font-family="Verdana" font-size="42.5" dy="-1em">

<textPath xlink:href="#MyPath">
      We go up, then we go down, then up again
    </textPath>

  </text>
<text dy="0em" font-family="Verdana" font-size="42.5">

<textPath xlink:href="#MyPath">
      SecondLine
    </textPath>

  </text>

  <!-- Show outline of the viewport using 'rect' element -->
  <rect x="1" y="1" width="998" height="298"
        fill="none" stroke="black" stroke-width="2" />
</svg>

【讨论】:

  • 这正是我需要做的!谢谢!
猜你喜欢
  • 2014-03-03
  • 2016-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-11
  • 2019-06-08
  • 2016-07-18
相关资源
最近更新 更多