简体   繁体   English

在父级中对齐SVG

[英]Aligning SVG within parent

I'm learning SVG and getting a bit of help from here. 我正在学习SVG,并从这里获得了一些帮助。 This is my code: http://jsfiddle.net/C8d34/6/ 这是我的代码: http : //jsfiddle.net/C8d34/6/

<svg viewBox="0 0 100 100"> /* this here */
  <circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />
</svg>

How can I align my circle so it sits horizontally aligned within the blue box and is aligned to the bottom vertically. 如何对齐我的圆圈,使其在蓝色框中水平对齐并垂直于底部对齐。 I believe it is something to do with: 我认为这与以下方面有关:

x="50" y="0"

But I haven't had any luck with that, it still doesn't sit in the right place. 但是我还没有运气,它仍然没有放在正确的地方。

svg {
    height: 50%;
    left: 50%;
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    -webkit-transform: translate(-50%, -50%);
    width: 50%;
}

Try this. 尝试这个。 Fiddle http://jsfiddle.net/C8d34/10/ 小提琴http://jsfiddle.net/C8d34/10/

svg {
vertical-align: middle;
display:inline-block;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM