Make overlapping div “not clickable” so that content below can be accessed?

后端 未结 4 666
囚心锁ツ
囚心锁ツ 2020-12-24 06:04

I am using a JPG overlay with a reduced opacity for an effect, however I want it as an effect only and make the content below that div clickable. Is that possible, thanks :)

相关标签:
4条回答
  • 2020-12-24 06:26

    one simple trick i have found, althoug not very w3c, is to encapsulate the div into a span and use that span class to make the overlay. That way the whole thing will be clickable , and the div will behave like a div

    0 讨论(0)
  • 2020-12-24 06:27

    Yes, its possible

    Use pointer-events: none along with conditional statements of CSS for IE11 (as it does not work in IE10 or below), you can get a cross browser compatible solution to achieve this.

    Using AlphaImageLoader, you can even put transparent .PNG/.GIFs in the overlay div and have clicks propagate through to elements lying bellow.

    CSS:

    pointer-events: none;
    background: url('your_transparent.png');
    

    IE11 conditional:

    filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='your_transparent.png', sizingMethod='scale');
    background: none !important;
    

    Here is a basic example page with all the code.

    0 讨论(0)
  • 2020-12-24 06:33

    No, it's not. The overlaying element will always intercept the click. One possible workaround is to bind a click event to the overlaying element, and then get the current mouse position & compare that to the position of the element underneath in order to determine whether or not that element should register a click. But chances are there is a much better way of accomplishing this. Without seeing your code, however, I have no way of knowing.

    0 讨论(0)
  • 2020-12-24 06:47

    Well there is pointer-events:none; but only few browsers modern browsers (and IE11) support it.

    https://developer.mozilla.org/en/CSS/pointer-events

    0 讨论(0)
提交回复
热议问题