首页 新闻 赞助 找找看

怎么将div层显示在页面中秧?

0
悬赏园豆:5 [已解决问题] 解决于 2009-12-11 09:30

我想把div层显示在我当前页面的正中间,而且它是漂在页面上的,不会占页面下面的内容的位置,请问该怎么设置啊?

问题补充: 我一个层开始是隐藏的,后来让它显示了,怎么让当前页面滚动到让这个层显示在页面中间停下?
flora_asp.net的主页 flora_asp.net | 初学一级 | 园豆:200
提问于:2009-12-07 14:19
< >
分享
最佳答案
-1
使用绝对定位,先设置DIV的定位上和左分别为50%,然后使用负边界,边界大小是DIV的高度和宽度的一半
代码如下:
position:absolute; 
width:1000px;height:600px;
left:50%; top:50%; margin-left:-500px; margin-top:-300px
收获园豆:4
Ray Wu | 初学一级 |园豆:5 | 2009-12-07 14:40
其他回答(4)
0

上面的回答应该再加上 z-index: 1; 这样表示他是漂在其他div之上的,当然其他的div的z-index要为0,默认情况下是0

收获园豆:1
LifeLight | 园豆:391 (菜鸟二级) | 2009-12-07 14:43
0
代码
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>显示遮盖层</title>
<style type="text/css">
.over
{width:600px;height:400px;margin-left:-300px;margin-top:-200px;position:absolute;top:50%;left:50%;z-index:1000;}
.hide
{display:none;}
.red
{background:red;}
</style>
<script type="text/javascript">
function show(){
document.getElementById(
"overDiv").style.display="block";
}
</script>
</head>
<body>
<input type="button" onclick="show();" value="show" />
<div class="over red hide" id="overDiv"></div>
</body>
</html>
大气象 | 园豆:79 (初学一级) | 2009-12-07 15:22
1

1楼正解。

I,Robot | 园豆:9783 (大侠五级) | 2009-12-07 17:28
0

1楼是对的

lisw | 园豆:313 (菜鸟二级) | 2009-12-07 20:25
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册