怎样让DIV定位在页面中间?就像<center>这样的定位? <div align=center>hello</div>or use span:<span align=center></span> 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用相对定位<div id=maindiv style="position:absolute;width:300;height:200;background:red"></div><script><!-- function pos(){document.all.maindiv.style.left=(parseInt(document.body.offsetWidth)-parseInt(document.all.maindiv.style.width))/2; document.all.maindiv.style.top=(parseInt(document.body.offsetHeight)-parseInt(document.all.maindiv.style.height))/2;} pos();//--></script> <div id=maindiv style="position:absolute;width:300;height:200;background:red"></div><script><!--maindiv.style.left=(document.body.clientWidth-maindiv.clientWidth)/2;maindiv.style.top=(document.body.clientHeight-maindiv.clientHeight)/2//--></script> <HTML><script>function divcenter(){document.all.mxh.style.left=(Math.round((document.body.scrollWidth-200)/2)).toString()+"px"}</script><body onload="divcenter()" onresize=divcenter()><table width=100%><tr><td>test</td></tr></table><div id=mxh style="position:absolute;left:200px;top:30px;width:200px;height:200px;background-color:navy;border:2px">测试文字</div></HTML> <HTML><script>function divcenter(){document.all.mxh.style.left=(Math.round((document.body.scrollWidth-200)/2)).toString()+"px"}</script><body onload="divcenter()" onresize=divcenter()><table width=100%><tr><td>test</td></tr></table><div id=mxh style="position:absolute;left:200px;top:30px;width:200px;height:200px;background-color:orange;border:2px">不随窗口变化,永远居中的层</div></HTML> 为什么我写的脚本在ie8下不能正常显示 网页自动跳到淘宝客 HTML select的上移下移该如何写算法? 给A标签添加事件出错 图片加载的错误处理 如何得到父对象 怎么样捕获一个按纽的按下事件 这个javascript应如何写? 用什么方法能遍历出一个对象的所有属性来 js 怎么将list 中数据按照自己想要的顺序显示在下拉列表中。 新手寻教材 学javascript看什么书好?
<script>
<!--
function pos(){
document.all.maindiv.style.left=(parseInt(document.body.offsetWidth)-parseInt(document.all.maindiv.style.width))/2;
document.all.maindiv.style.top=(parseInt(document.body.offsetHeight)-parseInt(document.all.maindiv.style.height))/2;
}
pos();
//-->
</script>
<script>
<!--
maindiv.style.left=(document.body.clientWidth-maindiv.clientWidth)/2;
maindiv.style.top=(document.body.clientHeight-maindiv.clientHeight)/2
//-->
</script>
<script>
function divcenter(){
document.all.mxh.style.left=(Math.round((document.body.scrollWidth-200)/2)).toString()+"px"
}
</script>
<body onload="divcenter()" onresize=divcenter()>
<table width=100%>
<tr>
<td>test
</td>
</tr>
</table>
<div id=mxh style="position:absolute;left:200px;top:30px;width:200px;height:200px;background-color:navy;border:2px">测试文字</div>
</HTML>
<script>
function divcenter(){
document.all.mxh.style.left=(Math.round((document.body.scrollWidth-200)/2)).toString()+"px"
}
</script>
<body onload="divcenter()" onresize=divcenter()>
<table width=100%>
<tr>
<td>test
</td>
</tr>
</table>
<div id=mxh style="position:absolute;left:200px;top:30px;width:200px;height:200px;background-color:orange;border:2px">不随窗口变化,永远居中的层</div>
</HTML>