各位,如何将悬停应用到滑动导航菜单?我有一个图标,在屏幕后面,使用变换,隐藏了带有文本的菜单的一部分,当您将鼠标悬停在该区域上时,我需要显示
背景颜色(参见屏幕截图):#2a2a2e;但是,由于带有图标的容器和文本在html结构中是分开的,我只能将效果应用到带有图标的容器,带有文本的区域不会被捕获,我尝试添加一个带有给它设置固定的宽度和高度,通过为容器分配事件处理程序来使用 JS 设置样式等,但这一切都不成功。总的来说,hover效果应该和codeWars网站上的一样,非常感谢!!!
HTML:
<div class="main-container">
<div class="icon-logo-unrated">
<img src="test/Unrated.svg" alt="img-icon-logo">
</div>
<div class="drop-right-menu">
<div class="home-page-label">Home
<div class="home-page-text">Go home to choose a different difficulty</div>
</div>
</div>
</div>
CSS:
/* main container */
.main-container {
position: absolute;
background-color: #121216;
width: 50px;
height: 100vh;
/*border-right: 1px solid #2a2a2e;*/
}
.icon-logo-unrated {
position: absolute;
display: flex;
justify-content: center;
align-items: center;
width: 50px;
height: 60px;
}
.drop-right-menu {
position: relative;
width: 320px;
height: 100vh;
background-color: #121216;
border-right: 1px solid #2a2a2e;
z-index: -1;
transition: transform 0.3s ease;
transform: translateX(-320px);
}
.main-container:hover .drop-right-menu {
transition: transform 0.3s ease;
transform: translateX(0);
}
/* TEXT */
.home-page-label {
font-size: 20px;
line-height: 1.5rem;
font-weight: 700;
color: #c1c1c1;
padding-left: 55px;
padding-top: 8px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.home-page-text {
padding-bottom: 0.25rem;
font-size: 15px;
line-height: 1rem;
white-space: nowrap;
color: #c1c1c1;
padding-top: 3px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.icon-logo-unrated:hover {
background-color: #2a2a2e;
}
那么我建议这个选项