How to overlay one div over another div

前端 未结 9 1896
旧时难觅i
旧时难觅i 2020-11-21 17:39

I need assistance with overlaying one individual div over another individual div.

My code looks like this:

9条回答
  •  猫巷女王i
    2020-11-21 18:02

    This is what you need:

    function showFrontLayer() {
      document.getElementById('bg_mask').style.visibility='visible';
      document.getElementById('frontlayer').style.visibility='visible';
    }
    function hideFrontLayer() {
      document.getElementById('bg_mask').style.visibility='hidden';
      document.getElementById('frontlayer').style.visibility='hidden';
    }
    #bg_mask {
      position: absolute;
      top: 0;
      right: 0;  bottom: 0;
      left: 0;
      margin: auto;
      margin-top: 0px;
      width: 981px;
      height: 610px;
      background : url("img_dot_white.jpg") center;
      z-index: 0;
      visibility: hidden;
    } 
    
    #frontlayer {
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      margin: 70px 140px 175px 140px;
      padding : 30px;
      width: 700px;
      height: 400px;
      background-color: orange;
      visibility: hidden;
      border: 1px solid black;
      z-index: 1;
    } 
    
    
    
    
      
        
    
      
      
        
    Click 'Show front layer' button


    Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing textsting text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text Testing text


    Now try to click on "Show front layer" button or the text box. It is not active.


    Use position: absolute to get the one div on top of another div.


    The bg_mask div is between baselayer and front layer.


    In bg_mask, img_dot_white.jpg(1 pixel in width and height) is used as background image to avoid IE browser transparency issue;


提交回复
热议问题