用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>  就是让网页居中而忆,有这么麻烦吗?

解决方案 »

  1.   

    <div id="dvShow" style="width:400;height:400;border:1 solid red;margin:auto"></div>
      

  2.   

    局中哪要这么麻烦呢,直接用css就行了
    以下方法参考:
    如果想做个固定宽度的网页并且想让网页水平居中的话,通常是这样:
    #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 。
      

  3.   

    把body内的内容都写到<div style="text-align:center;margin:auto;width:100%"></div> 这里就ok 了
      

  4.   

    body {width:800px;margin:0 auto;}
      

  5.   

    div{
    margin:0 auto;
    }
    body{
    text-align:center;
    }
      

  6.   


    同意,写个CSS就可以了。
      

  7.   

    加個層DIV 想怎麼就怎麼。
      

  8.   

    style="text-align:center;margin:0 auto;width:100%"
      

  9.   

    Z,老问题了
    if(window.screen.width>900)
    {document.write("<style type=\"text/css\">body{margin-left:"+(window.screen.width-900)/2+"px}</style>");}
    </script>
      

  10.   

    <body>
    <center>
      內容
    </center>
    </body>
    這樣應該可以居中
      

  11.   


    if(window.screen.width>945)
    {document.write(" <style type=\"text/css\">body{margin-left:"+(window.screen.width-945)/2+"px} </style>");}
    </script>
      

  12.   

    <body>
    <center>
    ....
    </center>
    </body>