你可能认为它是重复的,但我不这么认为,因为我说的是表格而不是图像!
我尝试使用以下代码在 div 的中心水平和垂直设置一个表格。这些代码适用于图像,但是当我放置一个表格而不是图像时,它似乎看不到表格,然后将跨度大小设置为 100%,并且表格显示在 div 下方,而不是在 div 的中心。
代码:
<style>
.wraptocenter {
display: table-cell;
text-align: center;
vertical-align: middle;
width:155px;
height: 160px;
background-color:#999;
display: block;
}
.wraptocenter * {
vertical-align: middle;
}
.wraptocenter span {
display: inline-block;
height: 100%;
width: 1px;
}
</style>
<!--[if lt IE 8]><style>
.wraptocenter span {
display: inline-block;
height: 100%;
}
</style><![endif]-->
<div class="wraptocenter">
<span></span>
<table border="1" width=" 70%">
<tr height="10px">
<td width="10px" height="10px"></td>
<td width="10px" height="10px"></td>
</tr>
<tr height="10px">
<td height="10px"></td>
<td height="10px"></td>
</tr>
</table>
</div>
如果你放一张图片,一切都很好,但桌子不行!