是否可以部分覆盖该元素,但使其对光标可见?
Is it possible to partly cover the element, but leave it visible to the cursor?
在 template 中,我需要在菜单上实现叠加图像,但我想留下完全可用的菜单项,而不是部分。
现在实现了,只有按钮的上半部分可用https://arthurmiko.github.io/shadows_portfolio/
.elem {
display: inline-block;
width: 100px;
height: 100px;
background: #777;
transition: .3s;
}
.elem:hover {
cursor: pointer;
background: #f77;
}
.higher-box {
position: relative;
margin-top: -50px;
width: 308px;
height: 100px;
background: rgba(0, 0, 255, .9);
z-index: 1;
}
<div class="lower-box">
<a href="#"><div class="elem"></div></a>
<a href="#"><div class="elem"></div></a>
<a href="#"><div class="elem"></div></a>
</div>
<div class="higher-box"></div>
是否可以在蓝色块的重叠区域以某种方式让灰色块可供光标使用?
如果您可以删除 higher-box
的光标操作,您可以使用 .higher-box { pointer-events: none }
来完成
.elem {
display: inline-block;
width: 100px;
height: 100px;
background: #777;
transition: .3s;
}
.elem:hover {
cursor: pointer;
background: #f77;
}
.higher-box {
position: relative;
margin-top: -50px;
width: 308px;
height: 100px;
background: rgba(0, 0, 255, .9);
z-index: 1;
pointer-events: none;
}
<div class="lower-box">
<a href="#"><div class="elem"></div></a>
<a href="#"><div class="elem"></div></a>
<a href="#"><div class="elem"></div></a>
</div>
<div class="higher-box"></div>
你可以使用伪元素,假设没有之前的堆叠上下文:
HTML
<div class="covered"></div>
<div class="covering"></div>
CSS
.covered{
width: 200px; height: 200px;
background: red;
position: relative;
}
.covered:hover{
background-color: green;
}
.covering{
width: 200px; height: 200px;
background: blue;
position: relative;
top: -100px;
}
.covered:before{
content: "";
display: block;
position: absolute;
z-index: 300;
width: 100%; height: 100%;
}
在 template 中,我需要在菜单上实现叠加图像,但我想留下完全可用的菜单项,而不是部分。
现在实现了,只有按钮的上半部分可用https://arthurmiko.github.io/shadows_portfolio/
.elem {
display: inline-block;
width: 100px;
height: 100px;
background: #777;
transition: .3s;
}
.elem:hover {
cursor: pointer;
background: #f77;
}
.higher-box {
position: relative;
margin-top: -50px;
width: 308px;
height: 100px;
background: rgba(0, 0, 255, .9);
z-index: 1;
}
<div class="lower-box">
<a href="#"><div class="elem"></div></a>
<a href="#"><div class="elem"></div></a>
<a href="#"><div class="elem"></div></a>
</div>
<div class="higher-box"></div>
是否可以在蓝色块的重叠区域以某种方式让灰色块可供光标使用?
如果您可以删除 higher-box
的光标操作,您可以使用 .higher-box { pointer-events: none }
.elem {
display: inline-block;
width: 100px;
height: 100px;
background: #777;
transition: .3s;
}
.elem:hover {
cursor: pointer;
background: #f77;
}
.higher-box {
position: relative;
margin-top: -50px;
width: 308px;
height: 100px;
background: rgba(0, 0, 255, .9);
z-index: 1;
pointer-events: none;
}
<div class="lower-box">
<a href="#"><div class="elem"></div></a>
<a href="#"><div class="elem"></div></a>
<a href="#"><div class="elem"></div></a>
</div>
<div class="higher-box"></div>
你可以使用伪元素,假设没有之前的堆叠上下文:
HTML
<div class="covered"></div>
<div class="covering"></div>
CSS
.covered{
width: 200px; height: 200px;
background: red;
position: relative;
}
.covered:hover{
background-color: green;
}
.covering{
width: 200px; height: 200px;
background: blue;
position: relative;
top: -100px;
}
.covered:before{
content: "";
display: block;
position: absolute;
z-index: 300;
width: 100%; height: 100%;
}