【发布时间】:2013-12-29 13:18:04
【问题描述】:
简单代码
<table class="box" border="1px">
<tr>
<td valign="top">
my content
</td>
</tr>
</table>
风格
.box {
width:300px;
height:300px;
background-color:#d9d9d9;
position:absolute;
margin-left:-150px;
/* half of width */
margin-top:-150px;
/* half of height */
top:50%;
left:50%;
}
(见this fiddle)
允许水平和垂直居中表格。但是,当窗口大小调整为小于表格时,即使显示滚动条,我也无法看到内容的顶部。为什么?
【问题讨论】:
-
因为负上边距?
-
尝试使用 % 而不是 px,这会给你的盒子一个响应式元素
-
@onetrickpony, @Beep :: 不,这些都不能解决这个问题...