網(wǎng)頁絕對居中的方法和代碼
發(fā)布日期:[2010/5/7] 編輯:奇億廣州網(wǎng)站建設(shè)
網(wǎng)頁在瀏覽器絕對居中的方法,代碼如下:
方法一:
<div style="position:absolute;left:expression((body.clientWidth-1000)/2);top:expression((body.clientHeight-600)/2);width:1000;height:600">
<table width=1000 height=600 border=0 align=center cellpadding=0 cellspacing=0><tr><td>
頁面內(nèi)容
</td></tr></table>
</div>
方法二:
body,html{height:100%;padding:0;margin:0;}
<table width=100% height=100% border=0 align=center cellpadding=0 cellspacing=0><tr><td>
<table width=800 height=600 border=0 align=center><tr><td>
頁面內(nèi)容
</td></tr></table>
</td></tr></table>
其中網(wǎng)頁絕對居中方法一中的代碼,層和表格里的width和height前后需對應(yīng);絕對居中方法二是采用表格居中屬性來實(shí)現(xiàn),用CSS定義外表格寬和高均為瀏覽器的100%,然后內(nèi)表格居中于外表格TD即可。