简体   繁体   English

我不能让孩子的 Z-index 高于父母的

[英]I can't get Z-index of child to be higher than parent's

So, simplifying my code, I have three elements.所以,简化我的代码,我有三个元素。 PS: I'm using Bootstrap for positioning. PS:我正在使用Bootstrap进行定位。

  1. A container with 2 rows, each row with 2 cols that sould be clickable .一个有 2 行的容器,每行有 2 个可点击的列。
  2. Another div on top of this container, used to center a button exactly in the middle (vertically and horizontally) relative to the container.此容器顶部的另一个 div,用于将按钮相对于容器准确地居中(垂直和水平)。

Example: HTML:示例: HTML:

    <div class="container game my-5">
        <div class="row">
            <div class="col square" id="a1" style="height: 40vh;"></div>
            <div class="col square" id="a2" style="height: 40vh;"></div>
        </div>
        <div class="hold-btn w-100 h-100 d-flex align-items-center justify-content-center">
            <button class="btn px-4 py-4" id="button">Button</button>
        </div>
        <div class="row">
            <div class="col square" id="a3" style="height: 40vh;"></div>
            <div class="col square" id="a4" style="height: 40vh;"></div>
        </div>
    </div>

CSS: CSS:

.game {
    position: relative;
}

#a1 {
    background-color: rgb(74, 74, 223);
}

#a3 {
    background-color: rgb(231, 56, 56);
}

#a2 {
    background-color: rgb(45, 175, 45);
}

#a4 {
    background-color: rgb(245, 245, 36);
}

.hold-btn {
    position: absolute;
    top: 0;
    left: 0;
}

.btn {
    background-color: rgb(175, 207, 207);
    z-index: 100;
}

.square {
    cursor: pointer;
}

My problem is: I can't get both the clickable cols AND the button to show on top of the container "game".我的问题是:我无法同时获得可点击的列和按钮以显示在容器“游戏”的顶部。 I've tried using z-index, but with two results:我试过使用 z-index,但有两个结果:

  1. I can move the container "game" to the front, but then my button won't show.我可以将容器“游戏”移到前面,但是我的按钮不会显示。
  2. I can move the button to the front, but then my cols will show but won't be clickable.我可以将按钮移到前面,但随后我的 cols 将显示但不可点击。
  3. I can't figure out how to put elements in this order, from back to front: "1: div hold-btn, 2-container game, 3-button"我不知道如何按这个顺序排列元素,从后到前:“1:div hold-btn,2-container game,3-button”

Any help, please?请问有什么帮助吗? :( :(

Maybe it's just isolated on the back of its parent.也许它只是在其父母的背面被隔离。

Try the style rule below, it may help:试试下面的样式规则,它可能会有所帮助:

isolation: isolate; // add this rule to element or its parent

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为一个父级的子元素赋予比另一个父级更高的z索引? - How can I give a child element of one parent a higher z-index than another parent? 使孩子的z索引比父母高 - Make child to have higher z-index than parent 使z-index子级高于父级 - Make z-index child higher than parent 当父级div的子级的z-index值高于两个值时,如何在其div上方堆叠父级div的值? - How to stack a parent div above a div whilst it's child has a higher z-index than both? 如何在另一个具有较高 z-index 的元素的子元素前面获得具有较低 z-index 的元素的子元素? - How can I get a child of an element with lower z-index on front of a child of another element with higher z-index? z索引和堆叠顺序-使孩子低于父母但高于叔叔 - z-index and stacking order - make child lower than parent but higher than uncle 如何为子元素提供比父元素更高的z-index - How to give a child element a higher z-index than the parent element 如何使parent1的子元素具有比父2的子元素更高的z索引(与其他父元素具有相同的z索引)? - How to make child elements from parent1 have a higher z-index than child elements from parent 2 (with same z-index as other parent)? 父级div类的z-index高于子级 - parent div class higher z-index than children 将子元素放置在z-index大于其父元素的元素上方 - Positioning a child element above an element having z-index greater than it's parent
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM