You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

父元素设pointer-events:none后,伪元素cursor:not-allowed无效问题

伪元素cursor:not-allowed不生效的解决办法

父元素设置pointer-events: none后,伪元素会继承这个属性,导致伪元素无法响应任何鼠标事件,所以你设置的cursor: not-allowed不会生效。

解决方法很简单,给伪元素单独加上pointer-events: auto,让它能独立响应鼠标事件:

修改后的CSS代码:

.pointer-events-none {
    position: relative;
    pointer-events: none;
}

.pointer-events-none:after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
    cursor: not-allowed;
    /* 添加这行让伪元素能响应鼠标事件 */
    pointer-events: auto;
}

这样伪元素就能覆盖在父元素上方,既保持父元素不响应鼠标事件,又能正常显示not-allowed光标。

内容的提问来源于stack exchange,提问作者Hau Chung

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 05:15:57