将图像水平居中显示 [英] Center image in div horizontally
本文介绍了将图像水平居中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在一个div( class =top_image
)中有一个 img
正确地在div的中间,但没有我尝试工作...
感谢任何帮助!
解决方案
这里发布的每个解决方案都假设你知道你的 img
,这是不常见的情况。
display:block $ c $ c> img
,并设置 margin-left:auto
, margin-right:auto
或 margin:0 auto
。
请注意,您还必须为外部设置一个初始 min-width
code> div
。
I have an img
in a div (class="top_image"
) and I want this image to be exactly in the middle of the div but nothing I try works...
Thanks for any help!
解决方案 Every solution posted here assumes that you know the dimensions of your img
, which is not a common scenario. Also, planting the dimensions into the solution is painful.
Simply set display: block
for the img
inside your div
, and also set margin-left: auto
, margin-right: auto
, or margin: 0 auto
. That's all.
Note, that you'll also have to set an initial min-width
for your outer div
.
这篇关于将图像水平居中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文