1e41f4b71Sopenharmony_ci# tspan
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci添加文本样式。
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ci>  **说明:**
7e41f4b71Sopenharmony_ci>  - 该组件从API version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
8e41f4b71Sopenharmony_ci>
9e41f4b71Sopenharmony_ci>  - 文本的展示内容需要写在元素标签内,可嵌套子元素标签tspan分段。
10e41f4b71Sopenharmony_ci>
11e41f4b71Sopenharmony_ci>  - 文本分段,只支持被父元素标签svg嵌套。
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci## 权限列表
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci## 子组件
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ci支持[tspan](js-components-svg-tspan.md)。
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci支持以下表格中的属性。
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci| 名称             | 类型                                 | 默认值   | 必填   | 描述                                       |
27e41f4b71Sopenharmony_ci| -------------- | ---------------------------------- | ----- | ---- | ---------------------------------------- |
28e41f4b71Sopenharmony_ci| id             | string                             | -     | 否    | 组件的唯一标识。                                 |
29e41f4b71Sopenharmony_ci| x              | <length>\|<percentage> | 0     | 否    | 设置组件左上角x轴坐标。                             |
30e41f4b71Sopenharmony_ci| y              | <length>\|<percentage> | 0     | 否    | 设置组件左上角y轴坐标。作为textpath子组件时失效。            |
31e41f4b71Sopenharmony_ci| dx             | <length>\|<percentage> | 0     | 否    | 设置文本x轴偏移。                                |
32e41f4b71Sopenharmony_ci| dy             | <length>\|<percentage> | 0     | 否    | 设置文本y轴偏移。作为textpath子组件时失效。               |
33e41f4b71Sopenharmony_ci| rotate         | number                             | 0     | 否    | 字体以左下角为圆心旋转角度,正数顺时针,负数逆时针。               |
34e41f4b71Sopenharmony_ci| font-size      | <length>                     | 30px  | 否    | 设置文本的尺寸。                                 |
35e41f4b71Sopenharmony_ci| fill           | <color>                      | black | 否    | 字体填充颜色。                                  |
36e41f4b71Sopenharmony_ci| opacity        | number                             | 1     | 否    | 元素的透明度,取值范围为0到1,1表示为不透明,0表示为完全透明。支持属性动画。 |
37e41f4b71Sopenharmony_ci| fill-opacity   | number                             | 1.0   | 否    | 字体填充透明度。                                 |
38e41f4b71Sopenharmony_ci| stroke         | <color>                      | black | 否    | 绘制字体边框并指定颜色。                             |
39e41f4b71Sopenharmony_ci| stroke-width   | number                             | 1px   | 否    | 字体边框宽度。                                  |
40e41f4b71Sopenharmony_ci| stroke-opacity | number                             | 1.0   | 否    | 字体边框透明度。                                 |
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci## 示例
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci```html
45e41f4b71Sopenharmony_ci<!-- xxx.hml -->
46e41f4b71Sopenharmony_ci<div class="container">
47e41f4b71Sopenharmony_ci  <svg >
48e41f4b71Sopenharmony_ci    <text x="20" y="500" fill="#D2691E" font-size="20">
49e41f4b71Sopenharmony_ci      zero text.
50e41f4b71Sopenharmony_ci      <tspan>first span.</tspan>
51e41f4b71Sopenharmony_ci      <tspan fill="red" font-size="35">second span.</tspan>
52e41f4b71Sopenharmony_ci      <tspan fill="#D2691E" font-size="40" rotate="10">third span.</tspan>
53e41f4b71Sopenharmony_ci    </text>
54e41f4b71Sopenharmony_ci    <text x="20" y="550" fill="#D2691E" font-size="20">
55e41f4b71Sopenharmony_ci      <tspan dx="-5" fill-opacity="0.2">first span.</tspan>
56e41f4b71Sopenharmony_ci      <tspan dx="5" fill="red" font-size="25" fill-opacity="0.4">second span.</tspan>
57e41f4b71Sopenharmony_ci      <tspan dy="-5" fill="#D2691E" font-size="35" rotate="-10" fill-opacity="0.6">third span.</tspan>
58e41f4b71Sopenharmony_ci      <tspan fill="#blue" font-size="40" rotate="10" fill-opacity="0.8" stroke="#00FF00" stroke-width="1px">forth span.</tspan>
59e41f4b71Sopenharmony_ci    </text>
60e41f4b71Sopenharmony_ci  </svg>
61e41f4b71Sopenharmony_ci</div>
62e41f4b71Sopenharmony_ci```
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ci```css
65e41f4b71Sopenharmony_ci/* xxx.css */
66e41f4b71Sopenharmony_ci.container {    
67e41f4b71Sopenharmony_ci    flex-direction: row;
68e41f4b71Sopenharmony_ci    justify-content: flex-start;
69e41f4b71Sopenharmony_ci    align-items: flex-start;
70e41f4b71Sopenharmony_ci    height: 1000px;
71e41f4b71Sopenharmony_ci    width: 1080px;
72e41f4b71Sopenharmony_ci}
73e41f4b71Sopenharmony_ci```
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_ci![zh-cn_image_0000001127125196](figures/zh-cn_image_0000001127125196.png)
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ci属性动画示例
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_ci```html
80e41f4b71Sopenharmony_ci<!-- xxx.hml -->
81e41f4b71Sopenharmony_ci<div class="container">
82e41f4b71Sopenharmony_ci  <svg>
83e41f4b71Sopenharmony_ci    <text y="300" font-size="30" fill="blue">
84e41f4b71Sopenharmony_ci      <tspan>
85e41f4b71Sopenharmony_ci        tspan attribute x|opacity|rotate
86e41f4b71Sopenharmony_ci        <animate attributeName="x" from="-100" to="400" dur="3s" repeatCount="indefinite"></animate>
87e41f4b71Sopenharmony_ci        <animate attributeName="opacity" from="0.01" to="0.99" dur="3s" repeatCount="indefinite"></animate>
88e41f4b71Sopenharmony_ci        <animate attributeName="rotate" from="0" to="360" dur="3s" repeatCount="indefinite"></animate>
89e41f4b71Sopenharmony_ci      </tspan>
90e41f4b71Sopenharmony_ci    </text>
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ci    <text y="350" font-size="30" fill="blue">
93e41f4b71Sopenharmony_ci      <tspan>
94e41f4b71Sopenharmony_ci        tspan attribute dx
95e41f4b71Sopenharmony_ci        <animate attributeName="dx" from="-100" to="400" dur="3s" repeatCount="indefinite"></animate>
96e41f4b71Sopenharmony_ci      </tspan>
97e41f4b71Sopenharmony_ci    </text>
98e41f4b71Sopenharmony_ci  </svg>
99e41f4b71Sopenharmony_ci</div>
100e41f4b71Sopenharmony_ci```
101e41f4b71Sopenharmony_ci
102e41f4b71Sopenharmony_ci```css
103e41f4b71Sopenharmony_ci/* xxx.css */
104e41f4b71Sopenharmony_ci.container {
105e41f4b71Sopenharmony_ci    flex-direction: row;
106e41f4b71Sopenharmony_ci    justify-content: flex-start;
107e41f4b71Sopenharmony_ci    align-items: flex-start;
108e41f4b71Sopenharmony_ci    height: 3000px;
109e41f4b71Sopenharmony_ci    width: 1080px;
110e41f4b71Sopenharmony_ci}
111e41f4b71Sopenharmony_ci```
112e41f4b71Sopenharmony_ci
113e41f4b71Sopenharmony_ci![zh-cn_image_0000001127285008](figures/zh-cn_image_0000001127285008.gif)
114e41f4b71Sopenharmony_ci
115e41f4b71Sopenharmony_ci```html
116e41f4b71Sopenharmony_ci<!-- xxx.hml -->
117e41f4b71Sopenharmony_ci<div class="container">
118e41f4b71Sopenharmony_ci  <svg>
119e41f4b71Sopenharmony_ci    <text>
120e41f4b71Sopenharmony_ci      <tspan x="0" y="550" font-size="30">
121e41f4b71Sopenharmony_ci        tspan attribute fill|fill-opacity
122e41f4b71Sopenharmony_ci        <animate attributeName="fill" from="blue" to="red" dur="3s" repeatCount="indefinite"></animate>
123e41f4b71Sopenharmony_ci        <animate attributeName="fill-opacity" from="0.01" to="0.99" dur="3s" repeatCount="indefinite"></animate>
124e41f4b71Sopenharmony_ci      </tspan>
125e41f4b71Sopenharmony_ci    </text>
126e41f4b71Sopenharmony_ci  </svg>
127e41f4b71Sopenharmony_ci</div>
128e41f4b71Sopenharmony_ci```
129e41f4b71Sopenharmony_ci
130e41f4b71Sopenharmony_ci![zh-cn_image_0000001127125198](figures/zh-cn_image_0000001127125198.gif)
131e41f4b71Sopenharmony_ci
132e41f4b71Sopenharmony_ci```html
133e41f4b71Sopenharmony_ci<!-- xxx.hml -->
134e41f4b71Sopenharmony_ci<div class="container">
135e41f4b71Sopenharmony_ci  <svg>
136e41f4b71Sopenharmony_ci     <text>
137e41f4b71Sopenharmony_ci       <tspan x="20" y="600" fill="red">
138e41f4b71Sopenharmony_ci         tspan attribute font-size
139e41f4b71Sopenharmony_ci         <animate attributeName="font-size" from="10" to="50" dur="3s" repeatCount="indefinite"></animate>
140e41f4b71Sopenharmony_ci       </tspan>
141e41f4b71Sopenharmony_ci    </text>
142e41f4b71Sopenharmony_ci  </svg>
143e41f4b71Sopenharmony_ci</div>
144e41f4b71Sopenharmony_ci```
145e41f4b71Sopenharmony_ci
146e41f4b71Sopenharmony_ci![zh-cn_image_0000001173164863](figures/zh-cn_image_0000001173164863.gif)
147e41f4b71Sopenharmony_ci
148e41f4b71Sopenharmony_ci```html
149e41f4b71Sopenharmony_ci<!-- xxx.hml -->
150e41f4b71Sopenharmony_ci<div class="container">
151e41f4b71Sopenharmony_ci  <svg>
152e41f4b71Sopenharmony_ci    <text>
153e41f4b71Sopenharmony_ci      <tspan x="20" y="650" font-size="25" fill="blue" stroke="red">
154e41f4b71Sopenharmony_ci        tspan attribute stroke
155e41f4b71Sopenharmony_ci        <animate attributeName="stroke" from="red" to="#00FF00" dur="3s" repeatCount="indefinite"></animate>
156e41f4b71Sopenharmony_ci      </tspan>
157e41f4b71Sopenharmony_ci    </text>
158e41f4b71Sopenharmony_ci    <text>
159e41f4b71Sopenharmony_ci      <tspan x="300" y="650" font-size="25" fill="white" stroke="red">
160e41f4b71Sopenharmony_ci        tspan attribute stroke-width-opacity
161e41f4b71Sopenharmony_ci        <animate attributeName="stroke-width" from="1" to="5" dur="3s" repeatCount="indefinite"></animate>
162e41f4b71Sopenharmony_ci        <animate attributeName="stroke-opacity" from="0.01" to="0.99" dur="3s" repeatCount="indefinite"></animate>
163e41f4b71Sopenharmony_ci      </tspan>
164e41f4b71Sopenharmony_ci    </text>
165e41f4b71Sopenharmony_ci  </svg>
166e41f4b71Sopenharmony_ci</div>
167e41f4b71Sopenharmony_ci```
168e41f4b71Sopenharmony_ci
169e41f4b71Sopenharmony_ci![zh-cn_image_0000001127125200](figures/zh-cn_image_0000001127125200.gif)
170