[英]Bring element on top of modal backdrop
I am trying to build a guide functionality for my application.我正在尝试为我的应用程序构建指南功能。 As a part of this functionality, it is expected that a tooltip is shown next to the target HTML element and this target element is brought on top of modal backdrop that appears together with the tooltip.
作为此功能的一部分,预计工具提示会显示在目标 HTML 元素旁边,并且此目标元素会出现在与工具提示一起出现的模态背景之上。
The problem is that after significant effort I still cannot make HTML element show on top of the modal backdrop.问题是,经过大量努力,我仍然无法在模态背景上显示 HTML 元素。 Simple tricks like
z-index: 10000;important: position: relative
do not help.像
z-index: 10000;important: position: relative
这样的简单技巧没有帮助。 Also changing parent elements' z-index
by disabling it in Firefox Developer Tools (and leaving z-index: 10000;important: position: relative
for the target element that is supposed to be on top of the modal backdrop) does not help.此外,通过在 Firefox 开发人员工具中禁用父元素的 z-index 来更改父元素的
z-index
(并保留z-index: 10000;important: position: relative
对于应该位于模态背景顶部的目标元素)也无济于事。
HTML of the application is quite complex with many elements.应用程序的 HTML 非常复杂,包含许多元素。 But I want to be able to "highlight" any given element by bringing it on top of the modal overlay knowing only its id.
但是我希望能够“突出显示”任何给定的元素,方法是把它放在模态叠加层的顶部,只知道它的 id。 Is there an easy way to do that with JavaScript/React?
有没有一种简单的方法可以用 JavaScript/React 做到这一点?
Hopefully there is a way to do this without modifying the DOM, which would be highly preferable.希望有一种方法可以在不修改 DOM 的情况下做到这一点,这将是非常可取的。
UPD: Code demo - press hat button to show guide/tooltips UPD:代码演示- 按帽子按钮显示指南/工具提示
Remove the z-index from .form-wrapper
and apply relative position with z-index for the targetted elements.从
.form-wrapper
中删除 z-index 并为目标元素应用相对 position 和 z-index。
I did this by adding我通过添加来做到这一点
d.classList.add("tooltip-active-element");
to App.js@77到 App.js@77
Also added the class to the css file:还将 class 添加到 css 文件中:
.tooltip-active-element {
position: relative;
z-index: 2;
background: red;
}
and removed the z-index value from other classes, the key one being the .form-wrapper
class.并从其他类中删除 z-index 值,关键是
.form-wrapper
class。
Working demo: https://codesandbox.io/s/tooltip-z-index-forked-fg9pt工作演示: https://codesandbox.io/s/tooltip-z-index-forked-fg9pt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.