非常教程

SVG参考手册

分类 | Elements

textpath

除了以直线绘制的文本之外,SVG还包括沿着<path>元素的形状放置文本的功能。要指定要沿着a的形状呈现文本块,请将<path>包含给定文本的<textPath>元素包含在一个元素href引用的属性中<path>

用法上下文

分类

文本内容元素,文本内容子元素

允许的内容

字符数据和任意数量的以下元素,以任何顺序:描述性元素<a>,<altGlyph>,<动画>,<animateColor>,<set>,<tref>,<tspan>

属性

全局属性

  • Conditional processing attributes »
  • Core attributes »
  • Graphical event attributes »
  • Presentation attributes »
  • Xlink attributes »
  • class
  • style
  • externalResourcesRequired

具体属性

  • startOffset
  • method
  • spacing
  • href

DOM接口

这个元素实现了SVGTextPathElement接口。

例子

SVG

<svg 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">
    <textPath xlink:href="#MyPath">
      We go up, then we go down, then up again
    </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>

结果

产品规格

Specification

Status

Comment

Scalable Vector Graphics (SVG) 2The definition of '<textPath>' in that specification.

Candidate Recommendation

Scalable Vector Graphics (SVG) 1.1 (Second Edition)The definition of '<textPath>' in that specification.

Recommendation

Initial definition

浏览器兼容性

Feature

Chrome

Edge

Firefox (Gecko)

Internet Explorer

Opera

Safari

Basic support

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

?

Feature

Android

Firefox Mobile (Gecko)

IE Phone

Opera Mobile

Safari Mobile

Basic support

?

?

?

?

?

SVG

可缩放矢量图形是基于可扩展标记语言(标准通用标记语言的子集),用于描述二维矢量图形的一种图形格式。它由万维网联盟制定,是一个开放标准。