为什么不自动居中图片? [英] Why doesn't margin:auto center an image?
本文介绍了为什么不自动居中图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<html>
<head>
<title>Test</title>
</head>
<body>
<div>
<img src="queuedError.jpg" style="margin:auto; width:200px;" />
</div>
</body>
</html>
div
展开为100%应该,但图像不居中。为什么?
The div
expands to 100% as it should but the image does not center itself. Why?
推荐答案
因为您的图片是 inline-block元素 。您可以将其更改为 块级元素 ,例如this:
Because your image is an inline-block element. You could change it to a block-level element like this:
<img src="queuedError.jpg" style="margin:auto; width:200px;display:block" />
它将居中。
这篇关于为什么不自动居中图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文