Stacking with z-index, child over parent

I ran into this problem: fiddle . In short, I want the green block to be in the middle of the z-order, without having to change the HTML. So yellow at the bottom, green in the middle and red at the top.

Yellow, red and green fields representing elements

HTML:

<div class="parent">
    Chillin in the background
    <div class="child">
        I really want to be on top.
    </div>
</div>
<div class="other-guy"> I want to be in the middle! </div>

CSS

.parent {
    background-color: yellow;
    position: absolute;
    top: 0;
    left: 0;
    height: 200px;
    width: 200px;
    z-index: 1;
}
.child {
    background-color: red;
    position: relative;
    top: 10px;
    left: 20px;
    height: 50px;
    width: 150px;
    z-index: 100;
}
.other-guy {
    background-color: green;
    position: absolute;
    top: 40px;
    left: 100px;
    height: 200px;
    width: 200px;
    z-index: 50;
}

The longer story is that in my solution I use a bootstrap grid system to position the child so that everything is receptive. The middle layer is a Google Maps element that you need to manipulate the user. My previous solution had an absolutely positioned child on the map, which works, but I don’t know how to make it responsive.

, , .

, , Google Maps.

+4
2

div z- div. , , .

.parent {
    background-color: yellow;
    
    top: 0;
    left: 0;
    height: 200px;
    width: 200px;
    z-index: 1;
}
.child {
    background-color: red;
    position: relative;
    top: 10px;
    left: 20px;
    height: 50px;
    width: 150px;
    z-index: 2;
}
.other-guy {
    background-color: green;
    position: absolute;
    top: 40px;
    left: 100px;
    height: 200px;
    width: 200px;
    
}
<div class="parent">Chillin in the background
    <div class="child">I really want to be on top.</div>
</div>
<div class="other-guy">I want to be in the middle!</div>
+5

:

http://philipwalton.com/articles/what-no-one-told-you-about-z-index/

, , , .

, jquery , :

$(".other-guy").insertAfter(".child");
0

Source: https://habr.com/ru/post/1608198/


All Articles