title: Stacking order of elements affected by opacity
body: <p>How are <code>z-index</code> and <code>opacity</code> related when deciding stacking order of an element in HTML?</p>
  
  <p>when i keep <code>opacity</code> less than <code>1</code> on an element which is having some <code>z-index</code> say <code>999</code>. The element is going behind the element which is having no <code>z-index</code>.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(function() {
    $("#checkbox1").on("change", function() {
      $("#green-parent").toggleClass("add-opacity", this.checked);
    });
  });</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.green,
  .blue {
    position: absolute;
    width: 100px;
    line-height: 100px;
    text-align: center;
    color: white;
  }
  .green {
    z-index: 999999999;
    top: 50px;
    left: 50px;
    background: green;
  }
  .blue {
    top: 60px;
    left: 90px;
    background: blue;
  }
  .add-opacity {
    opacity: 0.99;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;input id="checkbox1" type="checkbox" value="1"&gt;
  &lt;label for="checkbox1"&gt;Add opacity to green box parent&lt;/label&gt;
  
  
  &lt;div id="green-parent"&gt;
    &lt;span class="green"&gt;Green&lt;/span&gt;
  &lt;/div&gt;
  &lt;div&gt;
    &lt;span class="blue"&gt;Blue&lt;/span&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>