用DIv+css 做的
也
body {
text-align:center;
} 了也<table align="center">...</table>了
看了他们用这个<Script language="javascript">
function init()
{
var dh = document.body.clientHeight;
var dw = document.body.clientWidth;
var h = document.all("dvShow").style.posHeight;
var w = document.all("dvShow").style.posWidth;
//alert(dh + ":" + dw + ":" + h + ":" + w);
var x = (dw-w)/2;
var y = (dh-h)/2;
//alert(x + ":" + y);
document.all("dvShow").style.posLeft = x;
document.all("dvShow").style.posTop = y;
}
//add this:
window.onresize="init()";
</script>
<body onload="init()">
<div id="dvShow" style="position:absolute;left:0;top:0;width:400;height:400;border:1 solid red"></div>
</body> 就是让网页居中而忆,有这么麻烦吗?
也
body {
text-align:center;
} 了也<table align="center">...</table>了
看了他们用这个<Script language="javascript">
function init()
{
var dh = document.body.clientHeight;
var dw = document.body.clientWidth;
var h = document.all("dvShow").style.posHeight;
var w = document.all("dvShow").style.posWidth;
//alert(dh + ":" + dw + ":" + h + ":" + w);
var x = (dw-w)/2;
var y = (dh-h)/2;
//alert(x + ":" + y);
document.all("dvShow").style.posLeft = x;
document.all("dvShow").style.posTop = y;
}
//add this:
window.onresize="init()";
</script>
<body onload="init()">
<div id="dvShow" style="position:absolute;left:0;top:0;width:400;height:400;border:1 solid red"></div>
</body> 就是让网页居中而忆,有这么麻烦吗?
以下方法参考:
如果想做个固定宽度的网页并且想让网页水平居中的话,通常是这样:
#content { width: 700px; margin: 0 auto }
你会使用 <div id=”content”> 来围上所有元素。这很简单,但不够好,IE6之前版本会显示不出这种效果。改CSS如下:
body { text-align: center } #content { text-align: left; width: 700px; margin: 0 auto }
这会把网页内容都居中,所以在Content中又加入了:text-align: left 。
margin:0 auto;
}
body{
text-align:center;
}
同意,写个CSS就可以了。
if(window.screen.width>900)
{document.write("<style type=\"text/css\">body{margin-left:"+(window.screen.width-900)/2+"px}</style>");}
</script>
<center>
內容
</center>
</body>
這樣應該可以居中
if(window.screen.width>945)
{document.write(" <style type=\"text/css\">body{margin-left:"+(window.screen.width-945)/2+"px} </style>");}
</script>
<center>
....
</center>
</body>