html - Child above object 是 Child's Parent 和 other object 之上的对象

标签 html css

我想要 div #under_child_above_parent#child 之下但在 #parent 之上和在 #under_all 之上。这种 HTML 格式可能吗?因为我需要将它格式化为这样的格式,因为这样更容易在 child 中定位复杂的东西。

#under_all {
    width:100%;
    height:100px;
    background-color:blue;
    z-index:2;
}

#under_child_above_parent {
    width:100%;
    height:50px;
    position:absolute;
    left:0;
    top:0;
    color:white;
    background-color:red;
    z-index:3;
}

.objectwithinobject {
    width:50%;
    height:50%;
    position:absolute;
    left:25%;
    top:100;
}

#parent {
    background-color:green;
    z-index:1;
}

#child {
    background-color:grey;
    color:yellow;
    z-index:4;
}
<div id="under_all">
</div>
<div id="under_child_above_parent">
    Has to go above #under_all (blue), under#parent (green) and under #child (grey).
</div>
<div id="parent" class="objectwithinobject">
    <div id="child" class="objectwithinobject">
    </div>
</div>

最佳答案

您可以通过从 #parent div 中删除 z-index:1; 来实现这一点。

#under_all {
    width:100%;
    height:100px;
    background-color:blue;
    z-index:2;
}

#under_child_above_parent {
    width:100%;
    height:50px;
    position:absolute;
    left:0;
    top:0;
    color:white;
    background-color:red;
    z-index:3;
}

.objectwithinobject {
    width:50%;
    height:50%;
    position:absolute;
    left:25%;
    top:0px;
}

#parent {
    background-color:green;
}

#child {
    background-color:grey;
    color:yellow;
    z-index:4;
}
<div id="under_all">
</div>
<div id="under_child_above_parent">
    Has to go above #under_all (blue), under#parent (green) and under #child (grey).
</div>
<div id="parent" class="objectwithinobject">
    <div id="child" class="objectwithinobject">
    </div>
</div>

关于html - Child above object 是 Child's Parent 和 other object 之上的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26360258/

相关文章:

php - 将复选框插入 PHP Post 数组

html - 无法跨表格单元格垂直对齐文本 (HTML)

html - 使 html svg 对象也成为可点击的链接(在 iphone 上)

javascript - 使用滚动更改静态定位的图像

html - 尝试将列表定位在设备友好页面的内联图像上

javascript - 使用 JavaScript 获取文档的真实大小

html - Firefox 渲染一些小于字体大小的字符

html - 使 css 页脚保持在内容下方

html - div 问题 : height not extending with contents

javascript - 使用 window.print() 打印输出到不同的打印机