Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 使用负边距,如何重叠div并将其隐藏?_Css_Html - Fatal编程技术网

Css 使用负边距,如何重叠div并将其隐藏?

Css 使用负边距,如何重叠div并将其隐藏?,css,html,Css,Html,我试图让一个div与另一个div重叠,并将文本隐藏在后面。即使我指定了背景颜色或图像,文本也会显示出来 我想让第二组隐藏第一组 我使用了一个负的边距,因为我的CMS使用了一个重复区域,我需要第二个div来向下推剩余的部分 谢谢 Mandy尝试使用位置:relative作为顶部文本DIV 下面是CSS: element.style { background: none repeat scroll 0 0 #FFFF00; margin-top: -38px; positi

我试图让一个div与另一个div重叠,并将文本隐藏在后面。即使我指定了背景颜色或图像,文本也会显示出来

我想让第二组隐藏第一组

我使用了一个负的边距,因为我的CMS使用了一个重复区域,我需要第二个div来向下推剩余的部分

谢谢


Mandy

尝试使用
位置:relative
作为顶部文本DIV

下面是
CSS

element.style {
    background: none repeat scroll 0 0 #FFFF00;
    margin-top: -38px;
    position: relative;
}
这就是我所做的

<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>

使用
z-index
position:relative

如果要隐藏该div,为什么要使用它?为什么不使用display:none?
.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;
}