当前位置: 动力学知识库 > 问答 > 编程问答 >

SVG change x,y (0,0) top left to the center of my image

问题描述:

How to change the center of an svg file ?

Actually when I set X or Y attributes of my svg image, these coordinates are based to the top left corner of my image and I want to set these by the center of my image.

Any idea ?

PS: I use an image with .svg extension

网友答案:

In your SVG, set the viewBox to -{width / 2}, -{height / 2}, width, height. Given a width of 600 and a height of 400, your SVG would include viewBox="-300 -200 600 400".

JSFiddle example using the HTML5 logo

分享给朋友:
您可能感兴趣的文章:
随机阅读: