如何使div与另一个div重叠?

时间:2018-11-07 09:16:40

标签: javascript html css

如何将div async function parseAutodeskSpec(contentsHtmlFile) { const contentsPage = cheerio.load(fs.readFileSync(contentsHtmlFile).toString()); const contentsSelector = '.content_htmlbody table td div div#divtreed0e338374 nobr .toc_entry a.treeitem'; const contentsReqs = contentsPage(contentsSelector) .map((idx, elem) => rp(contentsPage(elem).attr('href'))) .toArray(); const topicsReqs = await Promise.all(contentsReqs) .map(req => parseAutodeskTopics(req)); return await Promise.all(topicsReqs); } 保留在前台?

#inner-block
#block-1 {
  position: absolute;
  width: 200px;
  height: 200px;
  top: 10px;
  left: 10px;
  background-color: #999;
  z-index: 1;
}

#inner-block {
  position: relative;
  width: 100px;
  height: 100px;
  margin: 20px;
  background-color: #777;
  z-index: 100;
}

#block-2 {
  position: absolute;
  width: 200px;
  height: 200px;
  top: 60px;
  left: 60px;
  background-color: #666;
  z-index: 2;
}

2 个答案:

答案 0 :(得分:3)

一个简单的解决方案是像这样更新您的HTML:

<div id="block-1">
  <div id="inner-block"></div></div>
  <div id="block-2">
</div>

之所以起作用,是因为它确保block-2inner-block的顺序是相对于公共父级的; block-1

#block-1
{
  position: absolute;
  width: 200px;
  height: 200px;
  top: 10px;
  left: 10px;
  background-color: #999;
  z-index: 1;
}
#inner-block
{
  position: relative;
  width: 100px;
  height: 100px;
  margin: 20px;
  background-color: #777;
  z-index: 100;
}
#block-2
{
  position: absolute;
  width: 200px;
  height: 200px;
  top: 60px;
  left: 60px;
  background-color: #666;
  z-index: 2;
}
<div id="block-1">
  <div id="inner-block"></div>
  <div id="block-2"></div>
</div>

希望这会有所帮助!

答案 1 :(得分:0)

只需从$ tcsh -c "env ENV_VAR=${ENV_VAR} /command/to/run <args>" 中删除z-index。这将使#bloc-1属于.inner-block的同一堆栈上下文,而不是#bloc-1创建的堆栈上下文。

  

对于具有“ z-index:auto”的用户,将其视为已创建元素   新的堆栈上下文,但任何定位的后代和后代   实际创建新堆叠上下文的部分应被视为一部分   父级堆叠上下文,而不是新的 ref

这意味着这3个div将属于相同的堆叠上下文,因此我们可以根据需要选择任意顺序

#bloc-1
#block-1 {
  position: absolute;
  width: 200px;
  height: 200px;
  top: 10px;
  left: 10px;
  background-color: #999;
}

#inner-block {
  position: relative;
  width: 100px;
  height: 100px;
  margin: 20px;
  background-color: #777;
  z-index: 100;
}

#block-2 {
  position: absolute;
  width: 200px;
  height: 200px;
  top: 60px;
  left: 60px;
  background-color: #666;
  z-index: 2;
}