日期:2014-05-17  浏览次数:20704 次

div居中,仿照别人例子怎么不居中郁闷。
<html>  
<head>
<title> 页面自动居中问题 </title>
</head>
<body>

<p> &nbsp; </p>
<p> &nbsp; </p>
<p> &nbsp; </p>
<p> &nbsp; </p>
<p> &nbsp; </p>
<p> &nbsp; </p>
<p> &nbsp; </p>
<p> &nbsp; </p>
<p> &nbsp; </p>
<p> &nbsp; </p>
<p> &nbsp; </p>
<p> &nbsp; </p>
<p> &nbsp; </p>
<p> &nbsp; </p>
<p> &nbsp; </p>
<p> &nbsp; </p>
<p> &nbsp; </p>
<p> &nbsp; </p>
<p> &nbsp; </p>
<p> &nbsp; </p>
<p> &nbsp; </p> <!--这是为了拉长网页,察看滚动条件下的居中-->
<p> &nbsp; </p>
<p> &nbsp; </p>
<p> &nbsp; </p>
<p> &nbsp; </p>
<p> &nbsp; </p>
<p> &nbsp; </p>
<p> &nbsp; </p>
<p> &nbsp; </p>
<p> &nbsp; </p>
<DIV   style= "position:absolute;background-color:red;width:50px;height:40px;margin:auto;   "> 居中解决问题1 </DIV>
<div     style= "position:absolute;   left:0;   top:0;   width:100%;   height:100%;background-color:#333333; "> 覆盖全页面2 </div>
</body>
</html>
1居中:仿照别人用marign可是就是不居中.
2覆盖页面:我要的我滚动到那就覆盖他那,设置成100%可他还是不覆盖下面的郁闷。
怎么解决这两个问题啊。

------解决方案--------------------
<center>
.....
</center>

------解决方案--------------------
function scroll()
{
var div=document.getElementsByTagName( "DIV ")[0];
div.style.top=document.body.scrollTop;
setTimeout( "scroll() ",200);
}
window.onload=scroll();

------解决方案--------------------
<html>
<head>
<title> 页面自动居中问题 </title>
<style type= "text/css ">
<!--
body {text-align:center;}
-->
</style>
</head>
<body>
<div> </div>
</body>
</html>

------解决方案--------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">

<head>
<title> 页面自动居中问题 </title>
<style type= "text/css ">

body {text-align:center;}

#Layer1 {
padding :80px;
width:328px;
height:272px;
background-color:red;
z-index:1;
}

</style>
</head>
<body>
<div id= "Layer1 "> dsfsd </div>
</body>
</html>
------解决方案--------------------
<html>
<head>
<title> 页面自动居中问题 </title>
</head>
<body style= "text-align:center; ">

<p> &nbsp; </p>
<p> &nbsp; </p>