Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/32.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
Html 如何将div放在其他div上_Html_Css_Z Index - Fatal编程技术网

Html 如何将div放在其他div上

Html 如何将div放在其他div上,html,css,z-index,Html,Css,Z Index,我想将一个div置于另一个div之上 CSS: HTML: 家 问题是,当我将black_strip1类放在内部div上时,它出现在正确的位置,但在下一个div之前会出现一个空格。给出包含div的位置:relative和子div位置:绝对 现在将相对于父div定位子div(从父div的左上角开始) 例如 给出包含div的位置:相对和子div位置:绝对 现在将相对于父div定位子div(从父div的左上角开始) 例如 我希望它能帮助你 我希望它能帮助你 .fresh_bnr_img {

我想将一个div置于另一个div之上

CSS:

HTML:


问题是,当我将
black_strip1
类放在内部div上时,它出现在正确的位置,但在下一个div之前会出现一个空格。

给出包含div的
位置:relative
和子div
位置:绝对

现在将相对于父div定位子div(从父div的左上角开始)

例如


给出包含div
的位置:相对
和子div
位置:绝对

现在将相对于父div定位子div(从父div的左上角开始)

例如


我希望它能帮助你


我希望它能帮助你

.fresh_bnr_img {
  float:left;
  width:950px;
  text-align:center;
}

.black_strip1 {
  position:relative;
  top:20px;
  width:120px;
  height:50px;
  background:#000;
  opacity:0.5;
  z-index:999;
}
<div class="fresh_bnr_img">
  <div class="black_strip1">Home</div>
  <img src="images/banner-2.jpg" width="946" height="295" alt="fresh-banner" />
</div>
.fresh_bnr_img{
 position:relative;
 float:left;
 width:950px;
 text-align:center;
}


.black_strip1{
 position:absolute;
 top:20px; /* 20px from the top edge of .fresh_bnr_img*/
 left:0px; /* 0px from the left edge of .fresh_bnr_img*/
 width:120px;
 height:50px;
 background:#000;
 opacity:0.5;
 z-index:999;
}