Css 使用负边距,如何重叠div并将其隐藏?
我试图让一个div与另一个div重叠,并将文本隐藏在后面。即使我指定了背景颜色或图像,文本也会显示出来 我想让第二组隐藏第一组 我使用了一个负的边距,因为我的CMS使用了一个重复区域,我需要第二个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
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;
}