Javascript 无法隐藏z索引设置为1的同级元素
我有一个模态叠加在另一个元素上。下部元素上的“关闭”按钮的z索引设置为1。创建模式时,此原始关闭按钮仍嵌套在新模式及其新关闭按钮的顶部 我已经尝试在dom中获取这个元素并隐藏它,但由于它不是父元素,所以我不知道如何隐藏它 编辑:这是伪代码……问题是如何删除覆盖的同级元素Javascript 无法隐藏z索引设置为1的同级元素,javascript,html,css,reactjs,Javascript,Html,Css,Reactjs,我有一个模态叠加在另一个元素上。下部元素上的“关闭”按钮的z索引设置为1。创建模式时,此原始关闭按钮仍嵌套在新模式及其新关闭按钮的顶部 我已经尝试在dom中获取这个元素并隐藏它,但由于它不是父元素,所以我不知道如何隐藏它 编辑:这是伪代码……问题是如何删除覆盖的同级元素 <div> <div> <img style={{z-index: 1; position: fixed;}}>close button (sibling, this one ne
<div>
<div>
<img style={{z-index: 1; position: fixed;}}>close button (sibling, this one needs to be moved underneath or hidden)</img>
</div>
<div>
<div>
<div>
<img style={{z-index: 1; position: relative;}}>close button (popup modal)</img>
</div>
</div>
及
你想完成什么?您是否有可能使用CSS或SASS进行样式设置 固定位置应始终具有宽度 例如:
.fixed {
position: fixed;
top: 0;
left: 0;
width: 100%;
padding: 20px;
background: rgba(255,255,255,.5);
}
确保HTML和正文设置为宽度和高度100%
为固定关闭按钮提供更高的索引
另外,另一个简单的技巧是不要使用空div。只需将其包装为占位符,这样在检查元素时它就不会在源代码中输出。style={z-index:1;position:fixed;}->style={{zIndex:1,position:'fixed'}
React内联样式引用:这看起来根本不像React代码。一般来说,对于一个模态,您会选中this.state来打开或关闭模态,整个过程都会在实例化类返回的呈现中进行。此社区中没有足够的代表对此发表评论。
closeLessonBtn.style.display = null;
.fixed {
position: fixed;
top: 0;
left: 0;
width: 100%;
padding: 20px;
background: rgba(255,255,255,.5);
}