【发布时间】:2022-12-26 08:33:19
【问题描述】:
悬停在子元素 <button> 上,对父元素 <h2> 没有悬停效果
.parent {
display: block;
text-align: center;
font-weight: 700;
font-size: 31px;
letter-spacing: normal;
position: relative;
}
.parent:hover {
color: orange;
}
span {
line-height: unset;
vertical-align: baseline;
top: 0;
left: 0;
position: absolute;
color: transparent;
box-shadow: none;
z-index: 5;
}
span button {
position: absolute;
left: 0;
top: -20px;
color: #fff;
width: 30px;
height: 30px;
min-width: 30px;
min-height: 30px;
z-index: 5;
background: #0085ba !important;
border-radius: 50%;
border: 2px solid #fff;
box-sizing: border-box;
padding: 3px;
display: inline-block;
overflow: hidden;
}
<h2 class="parent">
Title
<span class="child">
<button>+</button>
</span>
</h2>
【问题讨论】:
-
您可能需要引入一些 Javascript 来防止冒泡。这是可以接受的吗?
-
@AHaworth 我想是的。我已经考虑过了。因为没有找到任何 css 的解决方案
标签: html css hover parent-child