是什么
pointer-events
CSS 属性指定在什么情况下 (如果有) 某个特定的图形元素可以成为鼠标事件的目标。
属性值
auto
: 默认值none
:元素永远不会成为鼠标事件的目标,实现穿透
以下属性只在svg中使用:
visiblePainted
visibleFill
visibleStroke
visible
painted
fill
stroke
all
例子
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>pointer-events</title>
<style>
.box {
width: 200px;
height: 200px;
}
.box1 {
background-color: rebeccapurple;
}
.box2 {
background-color: brown;
margin: -80px 40px 20px;
}
.box1:hover {
background-color: gold;
}
.box2:hover {
background-color: gold;
}
</style>
</head>
<body>
<div class="box box1"></div>
<div class="box box2"></div>
</body>
</html>
给第二个盒子加上pointer-events: none;