首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >当我停止悬停主项时,我的sidenav子菜单就会消失。

当我停止悬停主项时,我的sidenav子菜单就会消失。
EN

Stack Overflow用户
提问于 2020-04-09 22:05:26
回答 1查看 21关注 0票数 0

我试着做了一个sidenav,想把它变成一个下拉菜单,但是当我不再停留在主菜单上时,这个下拉菜单就消失了。

有人知道怎么解决我的问题吗?(另请注意,这不能通过单击主项目而不是悬停来解决,因为单击主项目会链接到另一个页面)。

下面是我的代码:

代码语言:javascript
运行
复制
/* Style the links inside the sidenav */
#mySidenav a {
    position: absolute; /* Position them relative to the browser window */
    left: -80px; /* Position them outside of the screen */
    transition: 0.3s; /* Add transition on hover */
    padding: 15px; /* 15px padding */
    width: 100px; /* Set a specific width */
    text-decoration: none; /* Remove underline */
    font-size: 12px; /* Increase font size */
    color: white; /* White text color */
    border-radius: 0 5px 5px 0; /* Rounded corners on the top right and bottom right side */
}


    

/* The about link: 20px from the top with a green background */
.Home {
    top: 20px;
    background-color: #4CAF50;
}
#Home a:hover {
    left: 0; /* On mouse-over, make the elements appear as they should */
}
.Info {
    top: 80px;
    background-color: #2196F3; /* Blue */
}
#Info a:hover {
    left: 0; /* On mouse-over, make the elements appear as they should */
}
.Producten {
    top: 140px;
    background-color: #f44336; /* Red */
}
#Producten a:hover {
    left: 0; /* On mouse-over, make the elements appear as they should */
}
    #Producten a:hover ~ DropdownGroepstraining {
        visibility: visible;
        width: 100px;
        height: 45px;
    }

.DropdownGroepstraining {
    top: 185px;
    margin-left: 140px;
    background-color: #f44336; /* Red */
    display: none;
}

.DropdownPrivetraining {
    top: 230px;
    margin-left: 140px;
    background-color: #f44336; /* Red */
    display: none;
}

.DropdownTrajectopmaat {
    top: 275px;
    margin-left: 140px;
    background-color: #f44336; /* Red */
    display: none;
}
.Trainers {
    top: 200px;
    background-color: #555 /* Light Black */
}
#Trainers a:hover {
    left: 0; /* On mouse-over, make the elements appear as they should */
}
.DropdownPieter {
    top: 245px;
    margin-left: 140px;
    background-color: #555;
    display: none;
}
.DropdownLaura {
    top: 290px;
    margin-left: 140px;
    background-color: #555;
    display: none;
}
.DropdownYannick {
    top: 335px;
    margin-left: 140px;
    background-color: #555;
    display: none;
}
.DropdownSander {
    top: 380px;
    margin-left: 140px;
    background-color: #555;
    display: none;
}
.DropdownNick {
    top: 425px;
    margin-left: 140px;
    background-color: #555;
    display: none;
}
.Contact {
    top: 260px;
    background-color: purple;
}
#Contact a:hover {
    left: 0; /* On mouse-over, make the elements appear as they should */
}
.DropdownContactform {
    top: 305px;
    margin-left: 140px;
    background-color: purple;
    display: none;
}
.DropdownFacebook {
    top: 350px;
    margin-left: 140px;
    background-color: purple;
    display: none;
}
.DropdownInsta {
    top: 395px;
    margin-left: 140px;
    background-color: purple;
    display: none;
}
.FAQ {
    top: 320px;
    background-color: rgba(245, 240, 15, 0.7)
}
#FAQ a:hover {
    left: 0; /* On mouse-over, make the elements appear as they should */
}

a:hover ~ a {
    display: block;
}
代码语言:javascript
运行
复制
     <nav>
          <div id="mySidenav" class="sidenav">
  <div id="Home"><a href="Default.aspx" class="Home">Home</a></div>
  <div id="Info"><a href="Info.aspx" class="Info">Info</a></div>

<div id="Producten"><a href="Producten.aspx" class="Producten">Producten</a>
              <a href="Groepstraining.aspx" class=" DropdownGroepstraining">Groepstraining</a>
              <a href="Privetraining.aspx" class="DropdownPrivetraining">Privétraining</a>
              <a href="TrajectOpMaat.aspx" class="DropdownTrajectopmaat">Traject op maat</a>    
              </div>
  <div id="Trainers"><a href="Trainers.aspx" class="Trainers">Trainers</a>
              <a href="PieterGeerts.aspx" class="DropdownPieter">Pieter Geerts</a>
              <a href="LauraVanBaekel.aspx" class="DropdownLaura">Laura Van Baekel</a>
              <a href="YannickMaes.aspx" class="DropdownYannick">Yannick Maes</a>
              <a href="SanderGeerts.aspx" class="DropdownSander">Sander Geerts</a>
              <a href="NickVanCamp.aspx" class="DropdownNick">Nick Van Camp</a>
      </div>
  <div id="Contact"><a href="Contact.aspx" class="Contact">Contact</a>
              <a href="Contactformulier.aspx" class="DropdownContactform">Contactformulier</a>
              <a href="https://www.facebook.com/ttkempen/" target="_blank" class="DropdownFacebook"><img id="navfacebooklogo" src="images/facebooklogo.png" />Facebook</a>
              <a href="https://www.instagram.com/tt_kempen/?hl=nl" target="_blank" class="DropdownInsta"><img id="navinstagramlogo" src="images/instagramlogo.png" />Instagram</a>
    </div>  
  <div id="FAQ"><a href="FAQ.aspx" class="FAQ">FAQ</a></div>
</div> 
</nav>

有人知道怎么解决我的问题吗?(另请注意,这不能通过单击主项目而不是悬停来解决,因为单击主项目会链接到另一个页面)。

谢谢你抽出时间来,汤姆

EN

Stack Overflow用户

发布于 2020-04-09 22:14:04

问题是你选择的是锚点标签的悬停,它是子菜单的同级。改变你的

#制作a:hover {

#Producten:悬停{

这样,您选择的是父菜单的悬停,因此当悬停菜单和子菜单时,菜单将可见

票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61123037

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档