登录名:  密码:  验证码: 9504
设为首页 收藏本站 联系站长
2008年10月14日
农历戊子年(鼠)
九月十六
 首页 | 最新上传 | 新闻 | 购物商场 | 招聘求职 | HTML学习 | java学习 | IT新闻 | 黑客技术 | 域名和空间 | 流量统计 | 故事小说
 GIF动画制作 | 图片素材 | 源码下载 | 书籍下载 | 视频资料 | ASP | 数据库 | PHP | 基本电脑知识 | 迅雷资源 | 兼职 | 组网工程
 英语学习 | FLASH专区 | ASP.NET | VB | 综合资源网 | 驱动下载 | 游戏下载 | 网站模板网页美工 | 韩文学习 | 论坛
 特别推荐:产品报价  漂亮网站网址  图片素材
  我要查找:  
欢迎您来这里。每天学一点,每天进步一点!
Google
 当前位置:首页 >> HTML学习  >> javascript学习
怎样让DIV定位在页面中间?就像
这样的定位
来源:  发表日期:2008年1月31日 作者: 

 编辑:admin 级别: 司令 浏览次数:166
】    

问:
怎样让DIV定位在页面中间?就像<center>这样的定位?
______________________________________________________________________________________________
答1:
<div align=center>hello</div>
or use span:
<span align=center></span>
______________________________________________________________________________________________
答2:
用相对定位

<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>
______________________________________________________________________________________________
答3:
<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>

______________________________________________________________________________________________
答4:
对,就这样
______________________________________________________________________________________________
答5:
<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>


______________________________________________________________________________________________
答6:
<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>

(编辑:网站学习网)
Google
 ·上一篇文章: 帧(frame)之间参数传递,函数,
 ·下一篇文章: 到底什么是帧?怎么定义的
 该篇文章的评论
 暂无相关评论
 姓名:  邮箱:
 内容:
                
 相关文章
 · 怎么将checkbox, radio,
 · 怎样让DIV定位在页面中间
 · 甘特图对象的JavaScript
 · 再问怎样使一个已经打开
 · JAVASCRIPT怎样清除IE缓
 · js如何打开doc文件
 · 如何在父窗口调用子窗口
 · window.open怎样把打开窗
 · 可不可以用javascript为
 · window.open最大化的问题
 · 请问怎样设计层div的属性
 · 帧(frame)之间参数传递
 最新上传文章
 · 中文域名争夺激烈 
 · .Asia域名超30万 收
 · Alexa.
 · vista英文正式版的SN序列
 · NTLDR is mis
 · 装电脑的基本步骤
 · 第一次怎样自己组装电脑
 · fireworks 8序列号
 · Macromedia Firewo
 · 企业邮局 给企业注
 · ARP病毒的解决措施

服务说明 | 关于网站 | 联系我们 | 友情链接
网站学习网欢迎您!
http://www.studywebgood.com
浙ICP备07030755号 
联系邮箱:shuizhilang@126.com 如本网站侵犯了您的版权,请马上通知我.