html - CSS覆盖在页面主体上
问题描述
我有一个看起来像这样的 DOM:
<body>
<div id="main">
<iframe id="content"></iframe>
</div>
<div id="overlayWrapper">
<div id="overlay"><--THIS IS EMPTY DIV--></div>
</div>
</body>
在main
div 里面我还有一些其他的东西,这里不是很相关。现在,这些 div 具有以下 CSS 类。
#main {
width: 100%;
position: static;
z-index: 2;
overflow: hidden;
}
#content {
width: 100%;
height: 500px;
z-index: 3000; // This doesn't seem to help.
}
#overlayWrapper {
top: 0;
left: 0;
bottom: 0;
right: 0;
z-index: 1000; // This needs to be at least 1000 for overlay to cover all elements in the page
position: fixed; // This seems to cause the problem?!
}
#overlay {
opacity: 1;
will-change: opacity;
transition: opacity 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
top: 0;
left: 0;
bottom: 0;
right: 0;
z-index: -1;
position: fixed;
background-color: rgba(0, 0, 0, 0.5);
-webkit-tap-highlight-color: transparent;
}
现在,这似乎在某种程度上起作用,因为我看到我的叠加层具有出现在屏幕上的background-color
价值。rgba(0, 0, 0, 0.5)
有问题的部分是我无法单击iframe
.
position: fixed
我注意到这是因为#overlayWrapper
.
如果我删除它,那么我可以单击其中的内容,iframe
但现在覆盖层不再可见。
是否有可能以某种方式保留叠加层但再次使内容iframe
可点击?
我试图添加z-index: 3000;
到 iframe(即 to #content
),但这似乎不起作用。
有任何想法吗?
解决方案
position: relative
在<iframe>
元素上使用,因为z-index
属性与其相对属性一起起作用。
#content {
width: 100%;
height: 500px;
/* This doesn't seem to help */
z-index: 3000;
position: relative;
}
推荐阅读
- c++ - 必须使用 '.*' 或 '->*' 调用指向成员函数的指针
- swift - locationManager didExitRegion 在监控区域时从未调用 iBeaconRegion
- swiftui - SwiftUI 视图会更新,即使它不依赖于动态属性
- sql - 如何计算sql server中多列的方差?
- kotlin - 在 kotlin 中通过引用传递值
- angular - Angular Material Datatable 未对数据进行排序
- odbc - SAP HANA ODBC 驱动程序损坏
- swift - 如何将 myObject 转换为 AnyPublisher
? - html - 背景图片不覆盖网页背景
- java - Chaquopy:将 Java ArrayList/LinkedList 转换为 Python 数组