如何在 div 中居中 SVG? [英] How do I center an SVG in a div?
本文介绍了如何在 div 中居中 SVG?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 SVG,我试图将它放在一个 div 中.div 有一个宽度或 900px.SVG 的宽度为 400 像素.SVG 的 margin-left 和 margin-right 设置为 auto.不起作用,它就像左边距为 0(默认)一样.
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).
有人知道我的错误吗?
推荐答案
SVG 默认是内联的.将 display: block
添加到它,然后 margin: auto
将按预期工作.
SVG is inline by default. Add display: block
to it and then margin: auto
will work as expected.
这篇关于如何在 div 中居中 SVG?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文