为了账号安全,请及时绑定邮箱和手机立即绑定

怎么在svg里设置文字的center位置

怎么在svg里设置文字的center位置

holdtom 2019-03-28 18:17:49
怎么在svg里设置文字的center位置
查看完整描述

2 回答

?
湖上湖

TA贡献2003条经验 获得超2个赞

给你做了一个小demo。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

<html>

     

    <head>

        <style>

        div { width: 300px; height: 150px; background: #f06; font: bold 150% sans-serif; text-shadow: 0 1px 2px rgba(0,0,0,.5); overflow: hidden; resize: both; color: white; } 

        svg { width: 100%; height: 100%; pointer-events: none; }

        text { text-anchor: middle; pointer-events: auto; fill: currentColor; } 

        p { font: italic 100% Georgia, serif; }

        </style>

    </head>

    <body>

        <div>

            <svg>

                <text x="50%" y="50%" dy=".3em">居中文字</text></svg>

        </div>

    </body>

 

</html>


 


查看完整回答
反对 回复 2019-03-31
?
米琪卡哇伊

TA贡献1998条经验 获得超6个赞

示例
<?xml version="1.0" encoding="iso-8859-1"?>
<svg width="800" height="600">
<text style="fill:red;font-size:24pt" x="100" y="100";text-align:center>Hello World!</text>
</svg>

 


查看完整回答
反对 回复 2019-03-31
  • 2 回答
  • 0 关注
  • 1483 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信