悬停多级下拉列表

时间:2017-05-09 14:03:33

标签: html css dropdown

我试图创建一个带有子菜单的下拉菜单,当我将鼠标悬停时,子菜单会打开,但子菜单会一直显示在底部,而不是显示在其父级的右侧。

 <li class="dropdown">
   <a href="#" class="navbar-brand" data-toggle="dropdown">News <strong class="caret"></strong></a>
     <ul class="dropdown-menu">
       <li>
         <a href="#">A & E Passer </a>
           <ul>
             <li><a href="#">Elementary</a></li>
             <li><a href="#">Secondary</a></li>
            </ul>
        </li>

1 个答案:

答案 0 :(得分:1)

默认情况下

Bootstrap stacks submenu items vertically。我认为您正在寻找的是包含子菜单和下拉菜单的自定义CSS类的组合。

&#13;
&#13;
.dropdown-submenu {
  position: relative;
}

.dropdown-submenu>.dropdown-menu {
  top: 0;
  left: 100%;
  margin-top: -6px;
  margin-left: -1px;
  -webkit-border-radius: 0 6px 6px 6px;
  -moz-border-radius: 0 6px 6px 6px;
  border-radius: 0 6px 6px 6px;
}

.dropdown-submenu:hover>.dropdown-menu {
  display: block;
}

.dropdown-submenu>a:after {
  display: block;
  content: " ";
  float: right;
  width: 0;
  height: 0;
  border-color: transparent;
  border-style: solid;
  border-width: 5px 0 5px 5px;
  border-left-color: #cccccc;
  margin-top: 5px;
  margin-right: -10px;
}

.dropdown-submenu:hover>a:after {
  border-left-color: #ffffff;
}

.dropdown-submenu.pull-left {
  float: none;
}

.dropdown-submenu.pull-left>.dropdown-menu {
  left: -100%;
  margin-left: 10px;
  -webkit-border-radius: 6px 0 6px 6px;
  -moz-border-radius: 6px 0 6px 6px;
  border-radius: 6px 0 6px 6px;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>


<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu" style="display: block; position: static; margin-bottom: 5px; *width: 180px;">
  <li class="dropdown-submenu ">
    <a tabindex="-1" class="dropdown-toggle topLevel" data-toggle="dropdown" href="#">
        News
        <i class="icon icon-caret-right"></i>
      </a>
    <ul class="dropdown-menu">
      <li class="dropdown-submenu">
        <a href="#">A & E Passer</a>
        <ul class="dropdown-menu">
          <li><a href="#">Elementary</a></li>
          <li><a href="#">Secondary</a></li>
        </ul>
      </li>
    </ul>
  </li>
</ul>
&#13;
&#13;
&#13;