Bootstrap 引导减压未关闭

e7arh2l6  于 2022-12-07  发布在  Bootstrap
关注(0)|答案(1)|浏览(166)

在下面的例子中,我有两个问题:

**1.**我使用collapsedrop-down的混合来显示子菜单。但是在这个例子中我遇到了一个问题,当另一个子菜单打开时,我的子菜单不会自动关闭。

我不确定这个效果是否来自bs下拉菜单,我已经用accordion和data-parent测试过了,但这并不能解决问题。
有没有一个没有外部javascript的解决方案?只有Bootstrap原生JS组件?

**2.**在窄屏幕上,菜单被折叠,但如果下拉菜单直接显示在菜单项下而不是UI的末尾,效果会更好。

<script src="https://code.jquery.com/jquery-3.1.1.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />

<nav class="navbar navbar-default">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#mynavbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="brand" href="#">
        <span><img class="logo img-rounded" src="https://placeholdit.imgix.net/~text?txtsize=15&txt=Logo&w=100&h=100" alt="Logo"></span>
        <span class="xs-hidden">Brand</span>
      </a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="mynavbar">
      <div class="clearfix">
        <ul class="nav navbar-nav navbar-right">
          <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="collapse" data-target="#section-a" aria-expanded="false" aria-controls="section-a">Section A <span class="caret"></span></a>
          </li>
          <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="collapse" data-target="#section-b" aria-expanded="false" aria-controls="section-b">Section B <span class="caret"></span></a>
          </li>
          <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="collapse" data-target="#section-c" aria-expanded="false" aria-controls="section-c">Section C <span class="caret"></span></a>
          </li>
          <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="collapse" data-target="#section-d" aria-expanded="false" aria-controls="section-d">Section D <span class="caret"></span></a>
          </li>
        </ul>
      </div>
      <div class="collapsible-menu">
        <div class="collapse" id="section-a">
          <ul class="nav nav-tabs nav-justified">
            <li><a href="#">Item A.1</a>
            </li>
            <li><a href="#">Item A.1</a>
            </li>
            <li><a href="#">Item A.2</a>
            </li>
            <li><a href="#">Item A.3</a>
            </li>
            <li><a href="#">Item A.4</a>
            </li>
            <li><a href="#">Item A.5</a>
            </li>
          </ul>
        </div>
      </div>
      <div class="collapsible-menu">
        <div class="collapse" id="section-b">
          <ul class="nav nav-tabs nav-justified">
            <li><a href="#">Item B.1t</a>
            </li>
            <li><a href="#">Item B.2</a>
            </li>
            <li><a href="#">Item B.3</a>
            </li>
          </ul>
        </div>
      </div>
      <div class="collapsible-menu">
        <div class="collapse" id="section-c">
          <ul class="nav nav-tabs nav-justified">
            <li><a href="#">Item C.1</a>
            </li>
            <li><a href="#">Item C.2</a>
            </li>
            <li><a href="#">Item C.3</a>
            </li>
            <li><a href="#">Item C.4</a>
            </li>
          </ul>
        </div>
      </div>
      <div class="collapsible-menu">
        <div class="collapse" id="section-d">
          <ul class="nav nav-tabs nav-justified">
            <li><a href="#">Item D.1</a>
            </li>
            <li><a href="#">Item D.2</a>
            </li>
            <li><a href="#">Item D.3</a>
            </li>
          </ul>
        </div>
      </div>
    </div>
    <!-- /.navbar-collapse -->
  </div>
  <!-- /.container-fluid -->
</nav>
hsvhsicv

hsvhsicv1#

好吧,我自己找到了答案--我只想关闭这个帖子,展示解决方案:
第一个

相关问题