9

I made overlay div with:

position: absolute; top: 0; left: 0; widht: 100%; height: 100%;

Basically I want this overlay div to cover my whole page. And it does what I need, but I also need underlying divs to be unclickable. They are indeed unclickable but only in FF, Safari and Chrome. in IE and Opera you can still click buttons that are underneath.

Does anyone have any idea on how can I achieve this "unclickable underlying behaviour"?

Goran
  • 1,807
  • 7
  • 27
  • 41

6 Answers6

20
.class {pointer-events: none;}
kleopatra
  • 51,061
  • 28
  • 99
  • 211
Kadae
  • 300
  • 2
  • 9
  • 1
    This doesn't work in < IE11, and even in IE11 does not work on links (http://caniuse.com/#feat=pointer-events) – JDB May 19 '15 at 17:55
1

This can easily be done using javascript:

  • Create a div masking the entire page with a high z-index
  • Make the mask catch all clicks
  • When removing the mask, the page becomes clickable again.

This approach can of course be used on all dom elements, not just the body.

var mask = $('<div></div>')
  .css({
    position: 'absolute',
    width: '100%',
    height: '100%',
    top: 0,
    left: 0,
    'z-index': 10000
  })
  .appendTo(document.body)
  .click(function(event){
    event.preventDefault();
    return false;
   })

Working sample here: http://jsfiddle.net/GTPW3/3/

Lasse Skindstad Ebert
  • 3,370
  • 2
  • 29
  • 28
1

Add an onclick handler for the overlay div.

clorz
  • 1,103
  • 3
  • 14
  • 30
1

You also need to use z-index to ensure that your new div is on top of everything else. Without this attribute you are at the mercy of the browser in terms which one will be on top and receive the onclick

Also be aware of a known IE (older versions) bug that input type selection ignores z-index

mfeingold
  • 7,094
  • 4
  • 37
  • 43
1

If you're using something like jQuery, you can do something like

$("a:not(.overlay)").click(function(e) { e.preventDefault(); });
$("input:not(.overlay)").click(function(e) { e.attr("disabled", "disabled"); });

You'll give everything in your overlay (links, buttons, etc.) the overlay class, and this will effectively disable everything else on your page.

Jarrett Meyer
  • 19,333
  • 6
  • 58
  • 52
0

Tthe overlay CSS with:

z-index: 10000;

will take care of it.

Anne
  • 26,765
  • 9
  • 65
  • 71
Nidhin Bose J.
  • 1,092
  • 15
  • 28