使用文本对齐中心的中心图像? [英] Center image using text-align center?
本文介绍了使用文本对齐中心的中心图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
属性 text-align:center;
是使用CSS将图像居中的好方法吗?
Is the property text-align: center;
a good way to center an image using CSS?
img {
text-align: center;
}
推荐答案
text-align
属性适用于块容器,而不是内联元素, img
是一个内联元素。请参见 W3C规范。
That will not work as the text-align
property applies to block containers, not inline elements, and img
is an inline element. See the W3C spec.
Use this instead:
Use this instead:
img.center {
display: block;
margin: 0 auto;
}
这篇关于使用文本对齐中心的中心图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文