Displaying one div on top of another

后端 未结 5 1616
说谎
说谎 2020-12-13 04:13

I have some HTML with two divs:

\"\"
5条回答
  •  情深已故
    2020-12-13 05:07

    Have the style for the parent div and the child divs' set as following. It worked for my case, hope it helps you as well..

     

    in your JS:

    document.getElementById('parentDiv').style.position = 'relative';
    document.getElementById('backdrop').style.position = 'absolute';
    document.getElementById('curtain').style.position = 'absolute';
    document.getElementById('curtain').style.zIndex= '2';//this number has to be greater than the zIndex of 'backdrop' if you are setting any
    

    or in your CSS as in this working example:::

    #parentDiv{
      background: yellow;
      height: 500px;
      width: 500px;
      position: relative;
    }
    #backdrop{
      background: red;
      height: 300px;
      width: 300px;
      position: absolute;
    }
    #curtain{
      background: green;
      height: 100px;
      width: 100px;
      position: absolute;
      z-index: 2;
      margin: 100px 0px 150px 100px;
    }

    THIS IS PARENT DIV

    THIS IS BACKDROP DIV

    THIS IS CURTAIN DIV

提交回复
热议问题