2

我在一个透明元素下面有几个元素(它里面有一些可见的东西)。但似乎填充不允许鼠标事件通过。我有它,所以当鼠标悬停在一个较低的元素上时,它会改变颜色,然后当它离开时,它会慢慢变回原来的颜色。但是对于上面的元素覆盖它们的区域,悬停不会通过。有谁知道如何让这些事件传递到较低的元素?

这是我精简的代码。每当页面调整大小时都会制作网格框,因此它们总是填满背景。尽管是透明的,但诸如此类<div id="content">的东西在背景前面。所以这些盒子是可见的,但你不能与它们互动。

HTML

<body>
<div id="background">
    <canvas class="gridBox" id="grid1x1"></canvas>
    <canvas class="gridBox" id="grid2x1"></canvas>
    <canvas class="gridBox" id="grid3x1"></canvas>
    ...
    <canvas class="gridBox" id="grid18x8"></canvas>
</div>
<div id="header">
    <p id="logo"><img src="img/logo.png"></p>
</div>  
<div id="content">
    <p>Nothing here yet</p>
</div>  
<div id="footer">
</div>
</body>

CSS

body,html{
padding:0;
margin:0;
}
#background{
padding:0;
margin:0;
width:110%;
height:100%;
z-index:-1;
position:fixed;
top:0;
left:0;
overflow:visible;
line-height: 0;
}
.gridBox{
margin:0;
padding:0;
height:50px;
width:50px;
border:1px solid #000000;
background:black;
transition:background-color 1s linear;
}
.gridBox:hover{
background-color:green;
transition:background-color 0s linear;
}
4

1 回答 1

4

pointer-events: none;在 CSS 中尝试。#content 元素将不再检测鼠标,但下面的框会检测到它。

#content {
  pointer-events: none;
}
于 2013-12-24T05:32:26.767 回答