title: Disable background when div popup
body: <p>What I am trying to do is to show a div as a pop-up when I push a button and disable the background.</p>
  
  <p>My pop-up is working perfectly fine but the problem comes when I try to disable the background. To do this, I make use of the div called 'mask' which must to take up all the body. This div must be hidden at the beginning and to show it when somebody push the button.</p>
  
  <p>The thing is that this div (mask) is shown all the time, since the beginning.</p>
  
  <p>I have been trying to find a solution in internet and I found, among others, the following links:
  <a href="https://stackoverflow.com/questions/18386548/css-disable-background-when-div-popup">CSS Disable background when div popup</a> and
  <a href="https://stackoverflow.com/questions/17103723/disable-background-using-css-when-popup-appear">disable background using css when popup appear</a></p>
  
  <p>The first one doesn't have a solution and the solution of the second one doesn't fix my problem.</p>
  
  <p>This is my .jsp file:</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
          pageEncoding="ISO-8859-1"%&gt;
      &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
      &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
      &lt;head&gt;
      &lt;meta content="text/html; charset=utf-8" http-equiv="Content-Type"&gt;
  
      &lt;link href="css/styles.css" rel="stylesheet" type="text/css"&gt;
      &lt;link href="css/popup.css" rel="stylesheet" type="text/css"&gt;
  
      &lt;script src="js/jquery-2.1.0.js" type="text/javascript"&gt;&lt;/script&gt;
      &lt;script language="javascript" type="text/javascript" src="js/popup.js"&gt;&lt;/script&gt;
      &lt;/head&gt;
  
      &lt;body&gt;
          &lt;div id="pop"&gt;
              &lt;div id="close"&gt;X&lt;/div&gt;
              &lt;div id="contentPop"&gt;&lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div id="mask"&gt;
              &lt;div id="page-wrap"&gt;
                  ...
                  &lt;a class="minibtn" onclick="show();"&gt;Show pop-up&lt;/a&gt;
                              ...
  
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/body&gt;
  
      &lt;/html&gt;
  </code></pre>
  
  <p>I have omitted all the code that it is alien to the pop-up and I have replaced it for "...". </p>
  
  <p>The popup.css file: </p>
  
  <pre><code>#mask{
      z-index: 500;
      position: fixed;
      display: none; /* removes the element completely from the document, it doesn't take up any space. */
      /* visibility: hidden; -- hides the element, but it still takes up space in the layout. */
      background: transparent;
      background-color: #ccc;
      height: 100%;
      width: 100%;
      top: 0px;
      left: 0px;
  
  }
  
  #pop {
     z-index:2;
     position:absolute;
     border: 1px solid #333333;
     text-align:center;
     background:#ffffff;
  }
  
  #close {
     float:right;
     margin-right:5px;
     cursor:pointer;
     font:Verdana, Arial, Helvetica, sans-serif;
     font-size:12px;
     font-weight:bold;
     color:#FFFFFF;
     background-color:#666666;
     width:12px;
     position:relative;
     margin-top:-1px;
     text-align:center;
  }
  </code></pre>
  
  <p>And the popup.js file: </p>
  
  <pre><code>function show() {
      // Show pop-up and disable background using #mask
      $("#pop").fadeIn('slow');
      $("#mask").fadeIn('slow');
      // Load content.
      $.post("contentPopup.html", function(data) {
          $("#contentPop").html(data);
      });
  
  } 
  
  $(document).ready(function() {
      // Hide pop-up and mask
      $("#mask").hide();
      $("#pop").hide();
  
  
      // Size pop-up
      var img_w = 600;
      var img_h = 300;
  
      // width and height in css.
      $("#pop").css('width', img_w + 'px');
      $("#pop").css('height', img_h + 'px');
  
      // Get values ​​from the browser window
      var w = $(this).width();
      var h = $(this).height();
  
      // Centers the popup  
      w = (w / 2) - (img_w / 2);
      h = (h / 2) - (img_h / 2);
      $("#pop").css("left", w + "px");
      $("#pop").css("top", h + "px");
  
      // Function to close the pop-up
      $("#close").click(function() {
          $("#pop").fadeOut('slow');
          $("#mask").fadeOut('slow');
      });
  });
  </code></pre>
  
  <p>Thank you very much for your time and help. If there is any doubt, just let me know and I will try to explain it in a better way.</p>