html - 悬停时下拉菜单消失

标签 html css drop-down-menu hover

我的下拉菜单有问题,当我将鼠标悬停在它上面时,它会立即消失。对于此事,我将不胜感激。

* {
  margin: 0;
  padding: 0;
}

.clearfix:after {
  clear: both;
  content: ".";
  display: block;
  height: 0;
  visibility: hidden;
}

/* Menu */
header>hide:before {
  display: block;
  content: "";
  height: 30px;
  width: 30px;
  background: black url(burger.gif) no-repeat 0 0;
  background-size: contain;
  position: absolute;
  top: 20px;
  left: 0px;
  margin: 0px;
}

header>nav {
  display: none;
  position: absolute;
  text-align: left;
  top: 50px;
  left: 0;
  width: 200px;
  height: 193px;
  background-color: rgba(0,0,0,0.5);
  z-index: 999;
}

header>nav>ul {
  list-style-type: none;  
  margin: 0;
  padding: 0;
}

header>nav>ul>li {
  position: relative;
  float: none;
  bottom: 0;
  right: 0;
  background: url(menu.png) no-repeat top right;
  background-size: contain;
}

header>nav>ul>li>a {
  font-size: 1em; 
  font-weight: bold;
  text-decoration: none;
  color: white;
  margin: 0px 59px 0px 0px;
  display: inline-block;
  line-height: 48px;
  padding: 0px 24px;
  width: 60%;
  white-space: nowrap;
}

header>nav>ul>li>a:hover {
  background-color: rgb(146, 0, 0);
}

header>hide:hover + nav {
  display: block;
}
<!-- Header -->
<header class="clearfix">
<!-- Menu  -->
<hide></hide>
<nav>
  <ul>
    <li>
      <a href="#">123456</a>
    </li>
    <li>
      <a href="#">123456</a>
    </li>
    <li>
      <a href="#">123456</a>
    </li>
    <li>
      <a href="#">123456</a>
    </li>
  </ul>
</nav>

JSFiddle.

最佳答案

关于这个问题的提示,有时确保顶部 li 元素和子列表之间没有间隙,例如,如果您为顶部 li 元素指定边距,可能会导致问题,删除边距解决我的问题。

关于html - 悬停时下拉菜单消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47113203/

相关文章:

jquery - 2 个带有下拉菜单的堆叠按钮 100% 容器宽度

javascript - 在更改事件中查找下拉列表的先前值

javascript - 使用 jquery,匹配单个字符后跟冒号并包装在 span 标记中

javascript - 如何在不同选项卡上定期更新网站标题?

javascript - .html() jQuery 方法异常错误 - 在本地解析为空白空间,但在生产环境中不解析

CSS - 在类中设置多个 id

css - 在 iframe 中使用 Google Maps API 来防止 CSS 冲突?

html - 我如何在 html 中使用我的 css

javascript - 以编程方式在下拉列表中选择一个选项 <select>

javascript - 用于重复数据的 AngularJS rowspan