让层居中(定义DOCTYPE 的WEB页) 不需要用JS定义一个margin:auto;就行了比如<div style="margin:auto;width:100px;height:100px;backgroud-color:blue;"></div> 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 比如163邮箱的删除邮件提示框,上下左右都居中。在存在 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">的情况下该如何做到? 此回复为自动发出,仅用于显示而已,并无任何其他特殊作用楼主【shaoyk】截止到2008-06-26 22:16:44的历史汇总数据(不包括此帖):发帖数:2 发帖分:40 结贴数:1 结贴分:20 未结数:1 未结分:20 结贴率:50.00 % 结分率:50.00 % 楼主加油 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head></head><body> <div id="div1" style="background-color:blue;width:300px;height:100px;position:absolute;"></div></body><script>var theDiv = document.getElementById("div1");theDiv.style.left = (document.documentElement.offsetWidth-theDiv.offsetWidth)/2+"px";theDiv.style.top = (document.documentElement.offsetHeight-theDiv.offsetHeight)/2+"px";</script></html> 谢谢楼上朋友的回答。按照您给的代码,我加了几行代码,如下:可还是无法显示在当前网页的可视部分的正中。<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head></head><body> <div id="div1" style="background-color:blue;width:300px;height:100px;position:absolute;"></div><div style="height:2000px;"></div><input type=button value=click onclick='s();'/></body><script>function s(){var theDiv = document.getElementById("div1");theDiv.style.left = (document.documentElement.offsetWidth-theDiv.offsetWidth)/2+"px";theDiv.style.top = (document.documentElement.offsetHeight-theDiv.offsetHeight)/2+"px";}</script></html> jquery刷新页面局部的功能。求助 js实现的组织结构图帮忙把同级的节点横排 jquery自动补全 缓存问题 关于innerHTML window.onload=function()这个方法在一个页面中不能出现多次? 关于值的传递问题 能否突显下拉框被宽度限制遮住的部分? “每逢佳节倍思亲”,中秋佳节,和朋友们共欢 啊。。写了一天了。。ASP和DHTML结合的远程调用的简化,仿WebService做的。 自定义标签中使用变更问题 第一次散分:自定义js“数据库“ 有对jquery感兴趣的朋友吗?
楼主【shaoyk】截止到2008-06-26 22:16:44的历史汇总数据(不包括此帖):
发帖数:2 发帖分:40
结贴数:1 结贴分:20
未结数:1 未结分:20
结贴率:50.00 % 结分率:50.00 %
楼主加油
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
</head>
<body>
<div id="div1" style="background-color:blue;width:300px;height:100px;position:absolute;"></div>
</body>
<script>
var theDiv = document.getElementById("div1");theDiv.style.left = (document.documentElement.offsetWidth-theDiv.offsetWidth)/2+"px";
theDiv.style.top = (document.documentElement.offsetHeight-theDiv.offsetHeight)/2+"px";
</script>
</html>
按照您给的代码,我加了几行代码,如下:可还是无法显示在当前网页的可视部分的正中。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
</head>
<body>
<div id="div1" style="background-color:blue;width:300px;height:100px;position:absolute;"></div>
<div style="height:2000px;"></div><input type=button value=click onclick='s();'/>
</body>
<script>
function s(){
var theDiv = document.getElementById("div1");theDiv.style.left = (document.documentElement.offsetWidth-theDiv.offsetWidth)/2+"px";
theDiv.style.top = (document.documentElement.offsetHeight-theDiv.offsetHeight)/2+"px";
}
</script>
</html>