<a href="#" onclick="show('popup1')">Show popup (box-shadow)</a>
<a href="#" onclick="show('popup2')">Show popup (:before & :after)</a>

<div class="popup" id="popup1">
  <p>This is a popup!</p>
  <p>Overlay uses <b>box-shadow</b>.</p>
  <p>(Doesn't block elements on background)</p>
  <a href="#" onclick="hide('popup1')">Ok!</a>
</div>

<div class="popup" id="popup2">
  <p>This is a popup!</p>
  <p>Overlay uses <b>:before</b> and <b>:after</b> pseudo-classes.</p>
  <p>(This one does block elements on the background)</p>
  <a href="#" onclick="hide('popup2')">Ok!</a>
</div>
.popup {
  display: none;
  position: fixed;
  padding: 10px;
  width: 280px;
  left: 50%;
  margin-left: -150px;
  height: 180px;
  top: 50%;
  margin-top: -100px;
  background: #FFF;
  z-index: 20;
}

#popup1 {
  -webkit-box-shadow:  0px 0px 0px 9999px rgba(0, 0, 0, 0.5);
  box-shadow:  0px 0px 0px 9999px rgba(0, 0, 0, 0.5);
}

#popup2:after {
  position: fixed;
  content: "";
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  background: rgba(0,0,0,0.5);
  z-index: -2;
}

#popup2:before {
  position: absolute;
  content: "";
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  background: #FFF;
  z-index: -1;
}

/* From here on, just aesthetics */

body {
  background: #1abc9c;
  font-family: Arial, sans-serif;
  font-size: 120%;
  padding: 20px;
}

a,
a:visited {
  text-decoration: none;
  color: #FFF;
  font-weight: bold;
  display: block;
  margin: 10px 0;
}

a:hover,
a:active {
  text-decoration: underline;
}

.popup a,
.popup a:visited {
  color: #1abc9c;
}

p {
  margin: 1em 0;
}

p+p+p {
  font-size: 60%;
}
$ = function(id) {
  return document.getElementById(id);
}

var show = function(id) {
  $(id).style.display ='block';
}
var hide = function(id) {
  $(id).style.display ='none';
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.