这是我的代码。 请帮忙让它居中 而且,所有图片的大小都不一样
CSS:
body {
margin: 0px;
}
.wrapper {
text-align:center;
width: 100%;
height: 100%;
position: relative;
z-index: 21
}
.wrapper img {
display: table-cell;
vertical-align: middle;
}
HTML:
<div class="wrapper">
<img src="http://static.desktopnexus.com/thumbnails/196734-bigthumbnail.jpg" />
</div>
最佳答案
您只需要在图片上设置边距即可。
.wrapper img {
margin: auto;
}
此方法可用于任何对象,但请确保父级设置了宽度或高度。
关于CSS中间图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14083009/