Search code examples
htmlcsspopuppointer-events

Can I make the activation of a popup <div> do something to another <div>?


I have a link that will show a popup once clicked.

<a class="button" href="#popup1"><span id="contactspan"></span></a>

When the link is clicked an overlay shows up together with a popup .

DIV

<div id="popup1" class="overlay">
        <div class="popup">
            <h2>Contact</h2>

            <a class="close" href="#">×</a>
            <div class="content">
                Stuff in popup.
            </div>
        </div>
</div>

CSS

.box {
  width: 50%;
  margin: 0 auto;
  background: rgba(255,255,255,0.2);
  padding: 35px;
  border: 2px solid #fff;
  border-radius: 20px/50px;
  background-clip: padding-box;
  text-align: center;
}

.button {
  transition: all 0.3s ease-out;
}

.overlay {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.7);
  transition: opacity 500ms;
  visibility: hidden;
  opacity: 0;
}

.overlay:target {
  visibility: visible;
  opacity: 1;
}


.popup {
  margin: 70px auto;
  padding: 20px;
  background: #fff;
  border-radius: 5px;
  width: 50%;
  height: 50%;
  position: relative;
}

.popup h2 {
  margin-top: 0;
  color: #333;
  font-family: Tahoma, Arial, sans-serif;
}

.popup .close {
  position: absolute;
  top: 20px;
  right: 30px;
  font-size: 30px;
  font-weight: bold;
  text-decoration: none;
  color: #333;
}

.popup .content {
  max-height: 100%;
  overflow: auto;
}

My problem is that when the popup is visible, I can still click through the overlay and hit other links in my div container. Is there a way to set "pointer-events: none;" to be applied to div id="container" as long as my popup is visible?


Solution

  • This is called event bubbling, see

    What is event bubbling and capturing?

    You need to use:

    e.stopPropagation(); 
    

    In your JavaScript at the top of your event handler.