html - 如何使另一个下的 div 接收悬停事件?
问题描述
这是演示该问题的示例代码
.under {
position: absolute;
top: 10px;
left: 10px;
border: 2px solid blue;
width: 150px;
height: 150px;
}
.under:hover {
border: 10px solid green;
}
.over {
position: absolute;
z-index: 10;
top: 10px;
left: 10px;
width: 150px;
height: 150px;
border: 1px solid black;
}
<div>
<div class="under">
Hello!
</div>
<div class="over" data-comment="I am invisible">
</div>
</div>
当鼠标悬停在over
div 上时,我想要under
div 知道悬停事件,在这种情况下,相应地更改边框。
然而,over
div 显然正在拦截悬停事件。可以有一个纯css解决方案将悬停事件传递给under
div吗?
解决方案
指向救援的事件!只需设置pointer-events: none;
为.over
.
.under {
position: absolute;
top: 10px;
left: 10px;
border: 2px solid blue;
width: 150px;
height: 150px;
}
.under:hover {
border: 10px solid green;
}
.over {
position: absolute;
z-index: 10;
top: 10px;
left: 10px;
width: 150px;
height: 150px;
border: 1px solid black;
pointer-events: none;
}
<div>
<div class="under">
Hello!
</div>
<div class="over" data-comment="I am invisible">
</div>
</div>
请注意,这将使 .over div 忽略所有指针事件,因此 javascript 点击处理程序将不起作用
推荐阅读
- k-fold - AttributeError:“系列”对象没有“下”属性?
- macos - 在 macOS Big Sur 上安装可可豆荚时出错
- python - Django:您正在尝试添加一个不可为空的字段“slug”以在没有默认值的情况下发布;我们不能那样做
- javascript - 如何在不影响速度的情况下打开多个 puppeteer 实例
- linux-kernel - 内核源代码中的 usbfs 驱动程序
- google-chrome-extension - 谷歌扩展 - 发布后扩展不起作用
- azure - Microsoft Azure 存储 AzCopy:解析参数“复制”时出错
- vimeo - 如何检查我是否已达到 Vimeo 上允许的最大 http 请求?
- android - Android客户端将对象发送到服务器并且服务器确实收到了它们但客户端无法读取响应
- python - 使用 Selenium 抓取我当前的位置