如何将SVG放在div中心? [英] How do I center an SVG in a div?

查看:449
本文介绍了如何将SVG放在div中心?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SVG,我试图集中在一个div。 div的宽度或900像素。 SVG的宽度为400像素。 SVG的margin-left和margin-right设置为auto。

I have an SVG that I am trying to center in a div. The div has a width or 900px. The SVG has a width of 400px. The SVG has its margin-left and margin-right set to auto. Doesn't work, it just acts as if the left margin is 0 (default).

任何人都知道我的错误?

Anyone know my error?

推荐答案

SVG默认为内联。添加 display:block 到它,然后 margin:auto 将按预期工作。

SVG is inline by default. Add display: block to it and then margin: auto will work as expected.

这篇关于如何将SVG放在div中心?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆