5

I have a div that is positioned over a large chunk of the page, this causes the content underneath the div to no longer be selectable / clickable.

Is there a way to remedy this? ie: make a div not have any clickable functionality to it?

#page {
    width: 980px;
    padding: 0px;
    margin-top: 0px;
    margin-right: auto;
    margin-bottom: 0px;
    margin-left: auto;
    position: relative;
}
#overlay {
    margin: 0px;
    padding: 0px;
    height: 536px;
    width: 422px;
    position: absolute;
    top: -4px;
    right: -20px;
    background-image: url(../images/overlay_full.png);
    background-repeat: no-repeat;
    background-position: left top;
}
kilrizzy
  • 2,895
  • 6
  • 40
  • 63

4 Answers4

17

use css attribute "pointer-events" on the overlay:

#overlay {
   pointer-events: none;
}

see: HTML “overlay” which allows clicks to fall through to elements behind it

Community
  • 1
  • 1
Stephan Hepper
  • 420
  • 4
  • 6
1

If you really want the div to overlay the (clickable) stuff below, there is no decent way. An undecent way could be to hide the element on mousedown and reshow it onmouseup:

document.body.addEventListener("mousedown", function() { getElementById("overlay").style = "display:none;" });
document.body.addEventListener("mouseup", function() { getElementById("overlay").style = "display:block;" });

However be warned this is causing a reflow with every mousedown so will hit performance.

cellcortex
  • 3,166
  • 1
  • 24
  • 34
  • this prevents things like the mouse cursor changing to a hand when hovering over links, and prevents links from being underlined when hovered. The `pointer-events` answer is the right answer, as long as you don't need to support anything older than IE11. – Kip Sep 01 '17 at 01:30
0

You can use css z-index property to make the clickable objects overlap this mask. See how it works here:

http://www.w3schools.com/css/pr_pos_z-index.asp

amosrivera
  • 26,114
  • 9
  • 67
  • 76
0

There is/was a cheat method to do this were you put the overlay in a container div, set to:

position:fixed;
overflow:display;
width:0px;
height:0px;

Which subsequently causes it to have no hit area, but still be visible. However I don't know if this is cross-browser safe and may in fact be the result of a bug.

PhonicUK
  • 13,486
  • 4
  • 43
  • 62