使用SVG对图像进行居中

时间:2012-06-19 16:44:25

标签: image svg

我的.svg文件中有以下图片:

<image xlink:href="developer.mozilla.png" x="50%" y="50%" height="62" width="71"/>

我希望它显示在页面中间,但似乎左上角位于中间。如何让图像的中心显示在页面中央?

2 个答案:

答案 0 :(得分:15)

这样的事情应该有效:

<image xlink:href="developer.mozilla.png" x="50%" y="50%" height="62" width="71" transform="translate(-35.5,-31)"/>

答案 1 :(得分:4)

这是一种方式......

<svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
  <svg x="50%" y="50%" width="258px" height="221px" overflow="visible"> 
    <image x="-129px" y="-110.5px" width="258px" height="221px" xlink:href="http://images2.wikia.nocookie.net/__cb20110303182948/hogwartsrpg/images/9/95/KittenCareCat.png"/>
  </svg>
</svg>