admin管理员组文章数量:1134579
Is it possible for the child of a div set to pointer-events: none
to have pointer events?
I need the div that holds another div to allow pointer events to pass through, but for the div itself to still have events.
Is this possible?
Is it possible for the child of a div set to pointer-events: none
to have pointer events?
I need the div that holds another div to allow pointer events to pass through, but for the div itself to still have events.
Is this possible?
Share Improve this question edited Mar 24, 2022 at 15:37 Kostas Minaidis 5,2423 gold badges19 silver badges29 bronze badges asked Aug 12, 2012 at 7:21 fancyfancy 51.3k63 gold badges156 silver badges230 bronze badges4 Answers
Reset to default 243Yes, it's possible, and you basically just described how. Disable it for the parent and enable it for the child.
pointer-events
is supported in almost every browser, including IE11
Please note that pointer-events: all
is for SVG only.
For HTML, only auto
and none
are supported values.
.parent {
pointer-events: none;
}
.child {
pointer-events: auto;
}
<div class="parent">
<a href="#">Parent</a>
<div class="child">
<a href="#">Child</a>
</div>
</div>
Demo: http://jsfiddle.net/4gQkT/
On the child element's style, add
pointer-events: auto;
pointer-events: all
didn't work for me, and apparently applies to SVG elements only.
My solution:
.mouse-false * {
pointer-events: none;
}
<button class='mouse-false'>
<i>e</i> test
</button>
As a possible solution in some cases you can set
height: 0;
to parent element and let child element to overflow.
UPD. I've received -6 downvotes so I assume that my idea is not clear enough. Let me demonstrate it in action: https://jsfiddle.net/lllukom/4tpuv2ns/
In this example there is a flash message, which shows below the header and centered horizontally. To allow for content behind .flash-messages
to be interactive height: 0
is set.
There is one slight benefit in using height: 0
compared to pointer-events: none/all
so that when you are inspecting an element in chrome developer tools and hover over the link – the link is inspected instead of .flash-messages
container element.
本文标签:
版权声明:本文标题:javascript - Is it possible for the child of a div set to pointer-events: none to have pointer events? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736842020a1955143.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论