html svg矩形添加文字,如何在SVG矩形中放置和居中文本

SVG 1.2并未提供文本自动换行功能,开发者需要通过多个`text`元素或`tspan`结合`dy`属性手动实现文本在SVG矩形内的换行。Inkscape等工具能辅助完成形状内的文本流,并保持SVG 1.1兼容性。CSVG提出形状包裹文本的解决方案,但并非所有浏览器都支持。
摘要由CSDN通过智能技术生成

SVG 1.2微小的添加文本换行,但大多数SVG的实现,你会在浏览器中找到(Opera除外)没有实现这个功能。通常由您,开发人员手动定位文本。

SVG 1.1规范提供了对此限制的一个很好的概述,以及克服它的可能的解决方案:

Each ‘text’ element causes a single

string of text to be rendered. SVG

performs no automatic line breaking or

word wrapping. To achieve the effect

of multiple lines of text, use one of

the following methods:

The author or authoring package needs

to pre-compute the line breaks and use

multiple ‘text’ elements (one for each

line of text).

The author or authoring

package needs to pre-compute the line

breaks and use a single ‘text’ element

with one or more ‘tspan’ child

elements with appropriate values for

attributes ‘x’, ‘y’, ‘dx’ and ‘dy’ to

set new start positions for those

characters which start new lines.

(This approach allows us

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值