div竟要这样水平居中和垂直居中?
一直想用纯CSS定位DIV的居中找了找,用ID定义的:
<html> <head><script language=javascript> <!-- function SetPos() { window.DivIndex.style.pixelLeft=(document.body.offsetWidth - window.DivIndex.style.pixelWidth)/2; //定义水平居中 window.DivIndex.style.pixelTop=(document.body.offsetHeight - window.DivIndex.style.pixelHeight)/2; //定义垂直居中 } --> </script> </head> <body onload="SetPos();"> <div id=DivIndex style="POSITION: absolute;">居中显示的内容</div> </body> </html>
[此贴子已经被作者于2004-12-29 00:45:10编辑过]