html - 元素落后于背景?

标签 html css z-index

我有一个元素将其自身(及其所有子元素)放置在相应部分的背景后面。页面上的任何其他元素,甚至同一部分中的任何其他元素,我都没有遇到过这个问题。我有一个内嵌的背景颜色设置,只是为了确保这是正在发生的事情。它发生在所有浏览器中。感谢您提供的任何帮助。

<div id="homepage_servicesstrip">
    <div id="homepage_web_drops_wrap" style="background-color:red;">
    </div>
</div>

    #homepage_servicesstrip {
        background:url('home/images/gradient-services-background.png');
        background-size: auto 100%;
        position:absolute;
        margin-top:0px;
        width:100%;
        height:1050px;
        z-index:1;
    }
    #homepage_web_drops_wrap {
        position:absolute;
        margin-top:60%;
        margin-left:10%;
        height:500px;
        width:80%;
        z-index:60;
    }

最佳答案

z-index 首先计算 sibling ,然后计算 child 。例如 HTML

<div class="box">
    <div class="one box"></div>
</div>
<div class="box">
    <div class="two box"></div>
</div>
<div class="box">
    <div class="three box"></div>
</div>

CSS

   .box {
       z-index:1;
   }
   .two {
       z-index:1000000;
    }

.two 不会在 .three 之上,因为 .three 的 父级在 .two 的 父级之上。

DEMO

关于html - 元素落后于背景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16153283/

相关文章:

html - 为响应主题调整页面大小时无法使 Genesis 页脚小部件堆叠

css - 管道无法按预期运行 npm 脚本

javascript - Gatsby JS : Dynamically assign Style/Class based on current time?

jquery - 使用 CSS 使图像正确定位/分层

css - #map-canvas 的 child 可以在 map 前面吗?

php - 生成与 h1 标签完全相同的元页面标题

html - 标题菜单下拉菜单和图像不显示

javascript - 当计时器停止时禁用提交表单按钮 Javascript Html

html - 使用图像作为容器?

html - z-index 在 IE 中工作,但在 Edge 中不起作用