Html 将 svg 与屏幕中心对齐

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13373169/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 03:52:49  来源:igfitidea点击:

Align svg to center of screen

htmlsvg

提问by iJade

here is my svg

这是我的 svg

<svg id="svgMain" align="center" width="500" height="500"></svg> 

But its not aligned to the center.How to align it to the center of the screen.

但它没有与中心对齐。如何将其与屏幕中心对齐。

回答by Neps

Try CSS:

试试 CSS:

#svgMain {margin-left:auto; margin-right:auto; display:block;}

回答by Xin

Include it in a element.

将其包含在元素中。

<div text-align="center">
<svg id="svgMain" align="center" width="500" height="500"></svg>
</div>

This should work.

这应该有效。