How do I leave div overlapped to another div?











up vote
3
down vote

favorite












How do I leave the div #inner-block in the foreground?






#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>
<div id="block-2"></div>












share|improve this question
























  • I don't understand your question. What do you mean in the foreground? Small block to be on top of the bigger one?
    – Adi
    Nov 7 at 9:18










  • I don't think that is possible in the current setup, because the z-index of the parent of #inner-block is lower than #block-2. Can the elements be moved?
    – Swellar
    Nov 7 at 9:20












  • A simple solution would e just to move the inner block to be the child of the block-2.
    – Adi
    Nov 7 at 9:22















up vote
3
down vote

favorite












How do I leave the div #inner-block in the foreground?






#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>
<div id="block-2"></div>












share|improve this question
























  • I don't understand your question. What do you mean in the foreground? Small block to be on top of the bigger one?
    – Adi
    Nov 7 at 9:18










  • I don't think that is possible in the current setup, because the z-index of the parent of #inner-block is lower than #block-2. Can the elements be moved?
    – Swellar
    Nov 7 at 9:20












  • A simple solution would e just to move the inner block to be the child of the block-2.
    – Adi
    Nov 7 at 9:22













up vote
3
down vote

favorite









up vote
3
down vote

favorite











How do I leave the div #inner-block in the foreground?






#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>
<div id="block-2"></div>












share|improve this question















How do I leave the div #inner-block in the foreground?






#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>
<div id="block-2"></div>








#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>
<div id="block-2"></div>





#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>
<div id="block-2"></div>






javascript html css






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 7 at 13:43









j08691

164k20188212




164k20188212










asked Nov 7 at 9:16









Mano World

175




175












  • I don't understand your question. What do you mean in the foreground? Small block to be on top of the bigger one?
    – Adi
    Nov 7 at 9:18










  • I don't think that is possible in the current setup, because the z-index of the parent of #inner-block is lower than #block-2. Can the elements be moved?
    – Swellar
    Nov 7 at 9:20












  • A simple solution would e just to move the inner block to be the child of the block-2.
    – Adi
    Nov 7 at 9:22


















  • I don't understand your question. What do you mean in the foreground? Small block to be on top of the bigger one?
    – Adi
    Nov 7 at 9:18










  • I don't think that is possible in the current setup, because the z-index of the parent of #inner-block is lower than #block-2. Can the elements be moved?
    – Swellar
    Nov 7 at 9:20












  • A simple solution would e just to move the inner block to be the child of the block-2.
    – Adi
    Nov 7 at 9:22
















I don't understand your question. What do you mean in the foreground? Small block to be on top of the bigger one?
– Adi
Nov 7 at 9:18




I don't understand your question. What do you mean in the foreground? Small block to be on top of the bigger one?
– Adi
Nov 7 at 9:18












I don't think that is possible in the current setup, because the z-index of the parent of #inner-block is lower than #block-2. Can the elements be moved?
– Swellar
Nov 7 at 9:20






I don't think that is possible in the current setup, because the z-index of the parent of #inner-block is lower than #block-2. Can the elements be moved?
– Swellar
Nov 7 at 9:20














A simple solution would e just to move the inner block to be the child of the block-2.
– Adi
Nov 7 at 9:22




A simple solution would e just to move the inner block to be the child of the block-2.
– Adi
Nov 7 at 9:22












2 Answers
2






active

oldest

votes

















up vote
3
down vote













A simple solution would be to update your HTML like so:



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


This works because it ensures that the ordering of block-2 and inner-block is relative to a common parent; 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>





Hope this helps!






share|improve this answer





















  • there is more simple : stackoverflow.com/a/53196366/8620333
    – Temani Afif
    Nov 7 at 19:22


















up vote
0
down vote













Simply remove z-index from #bloc-1. This will make .inner-block to belong to the same stacking context of #bloc-1 and not the one created by #bloc-1.




For those with 'z-index: auto', treat the element as if it created a
new stacking context, but any positioned descendants and descendants
which actually create a new stacking context should be considered part
of the parent stacking context, not this new one.ref




This means that the 3 divs will belong to the same stacking context thus we can have any order we want






#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;
}

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








share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53186468%2fhow-do-i-leave-div-overlapped-to-another-div%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    3
    down vote













    A simple solution would be to update your HTML like so:



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


    This works because it ensures that the ordering of block-2 and inner-block is relative to a common parent; 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>





    Hope this helps!






    share|improve this answer





















    • there is more simple : stackoverflow.com/a/53196366/8620333
      – Temani Afif
      Nov 7 at 19:22















    up vote
    3
    down vote













    A simple solution would be to update your HTML like so:



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


    This works because it ensures that the ordering of block-2 and inner-block is relative to a common parent; 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>





    Hope this helps!






    share|improve this answer





















    • there is more simple : stackoverflow.com/a/53196366/8620333
      – Temani Afif
      Nov 7 at 19:22













    up vote
    3
    down vote










    up vote
    3
    down vote









    A simple solution would be to update your HTML like so:



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


    This works because it ensures that the ordering of block-2 and inner-block is relative to a common parent; 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>





    Hope this helps!






    share|improve this answer












    A simple solution would be to update your HTML like so:



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


    This works because it ensures that the ordering of block-2 and inner-block is relative to a common parent; 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>





    Hope this helps!






    #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>





    #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>






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 7 at 9:22









    Dacre Denny

    7,9154629




    7,9154629












    • there is more simple : stackoverflow.com/a/53196366/8620333
      – Temani Afif
      Nov 7 at 19:22


















    • there is more simple : stackoverflow.com/a/53196366/8620333
      – Temani Afif
      Nov 7 at 19:22
















    there is more simple : stackoverflow.com/a/53196366/8620333
    – Temani Afif
    Nov 7 at 19:22




    there is more simple : stackoverflow.com/a/53196366/8620333
    – Temani Afif
    Nov 7 at 19:22












    up vote
    0
    down vote













    Simply remove z-index from #bloc-1. This will make .inner-block to belong to the same stacking context of #bloc-1 and not the one created by #bloc-1.




    For those with 'z-index: auto', treat the element as if it created a
    new stacking context, but any positioned descendants and descendants
    which actually create a new stacking context should be considered part
    of the parent stacking context, not this new one.ref




    This means that the 3 divs will belong to the same stacking context thus we can have any order we want






    #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;
    }

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








    share|improve this answer

























      up vote
      0
      down vote













      Simply remove z-index from #bloc-1. This will make .inner-block to belong to the same stacking context of #bloc-1 and not the one created by #bloc-1.




      For those with 'z-index: auto', treat the element as if it created a
      new stacking context, but any positioned descendants and descendants
      which actually create a new stacking context should be considered part
      of the parent stacking context, not this new one.ref




      This means that the 3 divs will belong to the same stacking context thus we can have any order we want






      #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;
      }

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








      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        Simply remove z-index from #bloc-1. This will make .inner-block to belong to the same stacking context of #bloc-1 and not the one created by #bloc-1.




        For those with 'z-index: auto', treat the element as if it created a
        new stacking context, but any positioned descendants and descendants
        which actually create a new stacking context should be considered part
        of the parent stacking context, not this new one.ref




        This means that the 3 divs will belong to the same stacking context thus we can have any order we want






        #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;
        }

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








        share|improve this answer












        Simply remove z-index from #bloc-1. This will make .inner-block to belong to the same stacking context of #bloc-1 and not the one created by #bloc-1.




        For those with 'z-index: auto', treat the element as if it created a
        new stacking context, but any positioned descendants and descendants
        which actually create a new stacking context should be considered part
        of the parent stacking context, not this new one.ref




        This means that the 3 divs will belong to the same stacking context thus we can have any order we want






        #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;
        }

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








        #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;
        }

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





        #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;
        }

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






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 7 at 19:21









        Temani Afif

        59.5k93472




        59.5k93472






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53186468%2fhow-do-i-leave-div-overlapped-to-another-div%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Xamarin.form Move up view when keyboard appear

            Post-Redirect-Get with Spring WebFlux and Thymeleaf

            Anylogic : not able to use stopDelay()