gpt4 book ai didi

css - 冲突的悬停伪类

转载 作者:行者123 更新时间:2023-11-28 11:22:11 25 4
gpt4 key购买 nike

我有这样一种情况,我正在使用悬停伪类修改一个元素,当它的父元素悬停在它上面时,当它悬停在它上面时。不幸的是,它们有一个冲突的属性(都试图定义属性 transform),这就是为什么——我假设——当按钮悬停在按钮上但光标改变时缩放不起作用。是否可以解决仅使用 CSS 的问题?

body {
overflow: hidden;
}

#action-panel {
align-items: center;
box-sizing: border-box;
display: flex;
flex-direction: column;
justify-content: center;
padding: 20px 20px 20px 20px;
position: absolute;
right: 0;
transform: translateY(-50%);
top: 50%;
}

#action-panel:hover .action-button {
opacity: 1;
transform: translateX(0);
}

.action-button {
background-color: lightblue;
border-radius: 25px;
height: 50px;
margin-bottom: 20px;
opacity: 0;
transition: opacity 200ms ease-in-out, transform 200ms ease-in-out;
transform: translateX(calc(100% + 20px));
width: 50px;
}

.action-button:hover {
cursor: pointer;
transform: translateX(0) scale(1.2);
}

.action-button span {
font-size: 30px;
left: 50%;
position: relative;
transform: translate(-50%, -50%);
top: 50%;
}
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<div id="action-panel">
<div class="action-button"><span class="material-icons">3d_rotation</span></div>
<div class="action-button"><span class="material-icons">compare_arrows</span></div>
<div class="action-button"></div>
</div>

注意:

如果您从代码中看不出,您需要将光标移动到右边缘的中间才能看到我描述的效果。

最佳答案

通过在其前面添加#action-panel 来增加以下样式的特异性。在您的代码中,父项的悬停样式覆盖了子项的悬停样式。

 #action-panel .action-button:hover {
cursor: pointer;
transform: translateX(0) scale(1.2);
}

body {
overflow: hidden;
}

#action-panel {
align-items: center;
box-sizing: border-box;
display: flex;
flex-direction: column;
justify-content: center;
padding: 20px 20px 20px 20px;
position: absolute;
right: 0;
transform: translateY(-50%);
top: 50%;
}

#action-panel:hover .action-button {
opacity: 1;
transform: translateX(0);
}

.action-button {
background-color: lightblue;
border-radius: 25px;
height: 50px;
margin-bottom: 20px;
opacity: 0;
transition: opacity 200ms ease-in-out, transform 200ms ease-in-out;
transform: translateX(calc(100% + 20px));
width: 50px;
}

#action-panel .action-button:hover {
cursor: pointer;
transform: translateX(0) scale(1.2);
}

.action-button span {
font-size: 30px;
left: 50%;
position: relative;
transform: translate(-50%, -50%);
top: 50%;
}
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<div id="action-panel">
<div class="action-button"><span class="material-icons">3d_rotation</span></div>
<div class="action-button"><span class="material-icons">compare_arrows</span></div>
<div class="action-button"></div>
</div>

关于css - 冲突的悬停伪类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52090032/

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