2013-10-17 31 views
0

我想让一个div重叠另一个并隐藏文本后面。即使我指定背景颜色或图像,文字也会显示。使用负余量,我如何重叠div并隐藏它?

http://www.purple-mouse.co.uk/overlapdiv.php

我想第二个div来隐藏第一个。

我使用负边距作为我的CMS使用重复区域,我需要第二个div来推动剩余部分。

感谢

曼迪

+0

如果你想隐藏那个div。那你为什么要用它? – Sachin

+0

为什么不使用显示:无? –

回答

0

尝试使用position:relative顶级文本DIV。

下面是CSS

element.style { 
    background: none repeat scroll 0 0 #FFFF00; 
    margin-top: -38px; 
    position: relative; 
} 
0

这是我做什么,

<html> 
    <head> 
     <meta http-equiv="content-type" content="text/html; charset=us-ascii"> 
     <title></title> 
    </head> 
    <body> 
     <div class="bottom"> 
      Bottom text 
      <br> 
      <br> 
     </div> 
     <div class="top"> Top text </div> 
    </body> 
</html> 

CSS

.bottom { 
    z-index: 1; 
    position: relative; 
    background: none repeat scroll 0% 0% white; 
} 
.top{ 
    background: none repeat scroll 0% 0% yellow; 
    position: relative; 
    z-index: 0; 
    margin-top: -32px; 
} 

z-indexposition: relative