<分区>
我想垂直对齐 DIV 中的 IMG,但我看不出我做错了什么。 它适用于 FF 和 IE7,但其他浏览器只是将它对齐到顶部。 代码可以在这里找到:
<分区>
我想垂直对齐 DIV 中的 IMG,但我看不出我做错了什么。 它适用于 FF 和 IE7,但其他浏览器只是将它对齐到顶部。 代码可以在这里找到:
最佳答案
<style type="text/css">
.wraptocenter {
display: table-cell;
text-align: center;
vertical-align: middle;
width: ...;
height: ...;
}
.wraptocenter * {
vertical-align: middle;
}
</style>
<!--[if lt IE 8]>
<style>.wraptocenter span { display: inline-block; height: 100%;}/style>
<![endif]-->
<div class="wraptocenter"><span></span><img src="..." alt="..."></div>
检查一下 link出来,它确实帮助了我:
关于html - 在 DIV 中垂直对齐 img,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16686438/