当鼠标悬停在按钮上时,悬停效果会重叠按钮的图标和标签。我试图通过放置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
答案 0 :(得分:1)
首先,您将z-index:999
附加到img:hover
,这意味着您必须将图片悬停在其中才能应用。此外,您在:
后添加了额外的img:hover
,因此它就像img:hover:
。
此外,将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>