居中是CSS中最大的问题之一。但是,存在一些技巧:
要水平放置表格,您可以将左右边距设置为自动:
<style>
#test {
width:100%;
height:100%;
}
table {
margin: 0 auto; /* or margin: 0 auto 0 auto */
}
</style>
要垂直居中,唯一的方法是使用javascript:
var tableMarginTop = Math.round( (testHeight - tableHeight) / 2 );
$('table').css('margin-top', tableMarginTop) # with jQuery
$$('table')[0].setStyle('margin-top', tableMarginTop) # with Mootools