首页 > 其他 > 详细

DIV重叠 如何优先显示(div浮在重叠的div上面)

时间:2014-03-20 18:22:15      阅读:787      评论:0      收藏:0      [点我收藏+]

如果有2个div有重叠,默认是根据html解析顺序,最后加载的优先级最高(浮在最上面)。

 

问题:

如果想把前面加载的div显示在最上面?关键字:z-index

 

举例:

--原来的页面:first div是被second div盖住了:

<html>
<head>
<title>Test Div Overlap</title>
<style>
.first{
width: 366px;height: 384px;top:100px;left:100px;
position: relative;/*absolute*/
background-color:#CCCCCC;
text-align:right;
/*
z-index:2;
*/
}

.second{
width: 366px;height: 384px;top:0px;
position: absolute;
background-color:#999999;
}
</style>
</head>
<body>
<div id="first" class="first"><a href="#" title="Overlap by Second">Overlap by Second</a>&nbsp;&nbsp;first</div>
<div id="second" class="second">second&nbsp;</div>
</body>
</html>

解决方案:

1.需要将first的position设置为relative

2.将.first{}里面的z-index:2的注释取消

结果:

发现first div浮在second的上面了。

 

解释:

默认z-index是0,如果设置了z-index的值高于其他,就可以优先显示。

DIV重叠 如何优先显示(div浮在重叠的div上面),布布扣,bubuko.com

DIV重叠 如何优先显示(div浮在重叠的div上面)

原文:http://www.cnblogs.com/tomcatandjerry/p/3614062.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!