gpt4 book ai didi

html - 为什么悬停效果会重叠?

转载 作者:太空宇宙 更新时间:2023-11-04 07:55:04 24 4
gpt4 key购买 nike

当我将鼠标悬停在按钮上时,悬停效果会覆盖按钮的图标和标签。我试图通过放置 z-index: 999; 将图标/标签 div 层移动到悬停效果之上,但它不起作用。

HTML

<div class="service-wrapper">
<div class="services">
<a href="#"><div class="button">
<img src="https://png.icons8.com/?id=42205&size=36" class="iconBtn">
<div class="serv-name">TECHNICAL SUPPORT</div>
</div></a>
</div>
<div class="services">
<a href="#"><div class="button">
<img src="https://png.icons8.com/?id=7495&size=36" class="iconBtn">
<div class="serv-name">CUSTOMER SERVICE</div>
</div></a>
</div>
</div>

CSS

.button {
height: 40px;
width: 230px;
margin: 10px;
padding: 5px;
padding-right: 15px;
padding-left: 15px;
border-radius: 5px;
background: #ffbb11;
text-align: center;
color: #000000;
font-weight: bold;
display: flex;
align-items: center;
justify-content: space-around;
overflow: hidden;
position: relative;
}

a {
text-decoration: none;
}

.button::before,
.button::after {
background: rgba(255, 255, 255, 1.0);
content: '';
position: absolute;
}

.button::after {
height: 70px;
left: -22%;
top: 0;
transform: skew(50deg);
transition-duration: 0.3s;
transform-origin: top;
width: 0;
z-index: 0;
}

.button:hover:after {
height: 60px;
width: 325px;
}

.iconBtn{
max-height: 85%;
max-width: 85%;
}

img:hover: {
z-index: 999;
}

参见 JSFIDDLE

最佳答案

首先,您将 z-index:999 附加到 img:hover,这意味着您必须悬停图像才能应用。您还在 img:hover 之后添加了一个额外的 :,所以它就像 img:hover:

另外,在label中加入z-index:999确实可以解决问题。您会在此处看到结果:

.button {
height: 40px;
width: 230px;
margin: 10px;
padding: 5px;
padding-right: 15px;
padding-left: 15px;
border-radius: 5px;
background: #ffbb11;
text-align: center;
color: #000000;
font-weight: bold;
display: flex;
align-items: center;
justify-content: space-around;
overflow: hidden;
position: relative;
}
a {
text-decoration: none;
}
.button::before,
.button::after {
background: rgba(255, 255, 255, 1.0);
content: '';
position: absolute;
}

.button::after {
height: 70px;
left: -22%;
top: 0;
transform: skew(50deg);
transition-duration: 0.3s;
transform-origin: top;
width: 0;
z-index: 0;
}
.button:hover:after {
height: 60px;
width: 325px;
}
.iconBtn{
max-height: 85%;
max-width: 85%;
z-index: 999;
}
.serv-name{
z-index:999;
}
    <div class="service-wrapper">
<div class="services">
<a href="#"><div class="button">
<img src="https://png.icons8.com/?id=42205&size=36" class="iconBtn">
<div class="serv-name">TECHNICAL SUPPORT</div>
</div></a>
</div>
<div class="services">
<a href="#"><div class="button">
<img src="https://png.icons8.com/?id=7495&size=36" class="iconBtn">
<div class="serv-name">CUSTOMER SERVICE</div>

关于html - 为什么悬停效果会重叠?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47401756/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com