非常教程

SVG参考手册

属性 | Attributes

text-anchor

text-anchor属性用于对齐(开始,中间或结束对齐)相对于给定点的文本字符串。

text-anchor属性应用于给定元素中的每个单独文本块<text>。每个文本块具有初始当前文本位置,它表示在用户点坐标系统中从(取决于上下文)的应用情况,导致xy所述上<text>属性元件,以及任何xy上的<tspan><tref><altGlyph>属元件,明确地分配给所述第一渲染文本块中的字符,或者确定<textPath>元素的当前初始文本位置。

作为一个表现属性,它也可以直接在CSS样式表中作为属性使用。

用法说明

分类

呈现属性

开始| 中间| 结束| 继承

动画

规范性文件

SVG 1.1(第二版)

start

所呈现的字符对齐方式为:文本字符串的开始位置即当前文本的初始位置.对于拉丁文在其通常文本排列方向,这就相当于左对齐. 对于脚本像希伯来语和阿拉伯语这类自右向左排列的文字来说,这相当于右对齐. 对于亚洲某些垂直走向的文本来说,这相当于向上对齐。

middle

中间所呈现的字符对齐方式为:文本字符串的中间位置即当前文本的初始位置. (对于按路径排列的文本,会从概念上首先将其文本排列在一条直线上,确定该串中点位置后,然再将该文本映射到路径上,并且将之前确定的中点放置在当前文本的位置上 )

end

所呈现的字符对齐方式为:文本字符串的末尾即当前文本的初始位置.对于拉丁语通常的文字走向来说,这就相当于右对齐. 对于像希伯来语和阿拉伯语这类将文字自右向左排列的脚本来说,这相当于左对齐.

例子

<?xml version="1.0"?>
<svg width="120" height="120" viewBox="0 0 120 120"
     xmlns="http://www.w3.org/2000/svg" version="1.1">

    <!-- Materialisation of anchors -->
    <path d="M60,15 L60,110 M30,40 L90,40 M30,75 L90,75 M30,110 L90,110" stroke="grey" />
    
    
    <!-- Anchors in action -->
    <text text-anchor="start"
          x="60" y="40">A</text>

    <text text-anchor="middle"
          x="60" y="75">A</text>

    <text text-anchor="end"
          x="60" y="110">A</text>

    <!-- Materialisation of anchors -->
    <circle cx="60" cy="40" r="3" fill="red" />
    <circle cx="60" cy="75" r="3" fill="red" />
    <circle cx="60" cy="110" r="3" fill="red" />

<style><![CDATA[
text{
    font: bold 36px Verdana, Helvetica, Arial, sans-serif;
}
]]></style>
</svg>

Live sample

元素

The following elements can use the text-anchor attribute

  • Text content elements »

Edit this page on MDN

 © 2005–2017 Mozilla Developer Network and individual contributors.

Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.

https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/text-anchor

属性 | Attributes相关

1.accent-height(焦点高度)
2.accumulate(积累)
3.additive
4.alignment-baseline(对齐基线)
5.ascent
6.attributename(属性名字)
7.Attributes(属性)
8.attributetype(属性类型)
9.azimuth(方位)
10.basefrequency
11.baseline-shift(基线漂移)
12.baseprofile
13.begin(开始)
14.bias(偏压)
15.calcmode
16.class
17.clip(剪辑)
18.clip-path(剪辑路径)
19.clip-rule(剪辑规则)
20.clippathunits
21.color(颜色)
22.color-interpolation(彩色插值)
23.color-interpolation-filters(色彩插值滤波器)
24.color-profile(彩色轮廓)
25.color-rendering(显色)
26.contentscripttype
27.contentstyletype
28.cursor(光标)
29.cx
30.cy
31.d
32.diffuseconstant
33.direction(方向)
34.display(显示)
35.divisor
36.dominant-baseline(显性基线)
37.dur
38.dx
39.dy
40.edgemode
41.elevation
42.end
43.externalresourcesrequired
44.fill
45.fill-opacity
46.fill-rule
47.filter
48.filterres
49.filterunits
50.flood-color
51.flood-opacity
52.font-family
53.font-size
54.font-size-adjust
55.font-stretch
56.font-style
57.font-variant
58.font-weight
59.fr
60.from
61.fx
62.fy
63.gradienttransform
64.gradientunits
65.height
66.href
67.image-rendering
68.in
69.in2
70.k1
71.k2
72.k3
73.k4
74.kernelmatrix
75.kernelunitlength
76.kerning
77.keysplines
78.keytimes
79.lengthadjust
80.letter-spacing
81.lighting-color
82.limitingconeangle
83.local
84.marker-end
85.marker-mid
86.marker-start
87.markerheight
88.markerunits
89.markerwidth
90.mask
91.maskcontentunits
92.maskunits
93.max
94.min
95.mode
96.numoctaves
97.opacity
98.operator
99.order
100.overflow
SVG

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