我正在尝试找到一种方法来垂直居中我的SVG标签。
基本上,这是一个简化的SVG代码,我正在尝试居中:
<svg height="272" style="background-color:transparent;margin-left: auto; margin-right: auto;" width="130" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g style="font-size: 0.7em;" transform="scale(1 1) rotate(0) translate(0 270)">
<g id="1" style="font-size: 0.7em;">
<image height="32" width="32" x="49" xlink:href="../../images/JOB.GIF" y="-270"/>
</g>
</g>
</svg>
水平方向上把它放在中间对我来说没有问题,但我也想让它垂直居中。
我可以添加包装器,但我想知道一种通用的方法来做到这一点,不依赖于SVG大小或窗口大小。
我已经尝试了多种方法,但没有任何效果。
谢谢,
display
属性为inline
,因此如果您希望它的行为更像一个<div>
元素,您还需要指定svg { display: block }
。 - Erik Dahlström