具有多个拆分导航的Bootstrap 4导航栏不会折叠

时间:2018-07-18 17:37:45

标签: jquery twitter-bootstrap bootstrap-4 navbar hamburger-menu

在此版本中,数位板菜单中仅显示第一个菜单项。当我添加样式显示时:flex;到#navbarsExampleDefault,它显示了其他项目,但随后我无法折叠/隐藏菜单项。增加可见性:隐藏;仅隐藏菜单项,但占用相同的空间。我只包含一个菜单项以使其简短。

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="icon" href="#">
    <title>Home</title>
    <!--BOOTSTRAP-->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <link rel="stylesheet" type="text/css" href="css/style.css">
    <link href="https://fonts.googleapis.com/css?family=Roboto+Condensed:300,300i,400,400i|Roboto:300,300i,400,400i" rel="stylesheet">

                

            <button class="btn btn-link navbar-toggler collapsed" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 30 30" width="30" height="30" focusable="false"><title>Menu</title><path stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-miterlimit="10" d="M4 7h22M4 15h22M4 23h22"></path></svg>
            </button>

            <!-- SPLIT NAVBARS -->
            <div class="btn-group navbar-collapse collapse" id="navbarsExampleDefault">
              <button type="button" class="btn" id="button-1"><a href="csr-lfg.html">CSR at LF</a></button>
              <button type="button" class="btn dropdown-toggle dropdown-toggle-split" id="button-1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                <span class="sr-only">Toggle Dropdown</span>
              </button>
              <div class="dropdown-menu">
                <a class="dropdown-item" href="#">Submenu Item 1</a>
                <a class="dropdown-item" href="#">Submenu Item 2</a>
                <div class="dropdown-divider"></div>
                <a class="dropdown-item" href="#">Submenu Item 3</a>
                <a class="dropdown-item" href="#">Submenu Item 4</a>
                <a class="dropdown-item" href="#">Submenu Item 5</a>
                <a class="dropdown-item" href="#">Submenu Item 6</a>
              </div>
            </div>

        

1 个答案:

答案 0 :(得分:0)

您错过了bootstrap.js和pooper.js,可以在下拉菜单中找到更多信息(对于按钮)here

 <link rel="stylesheet"  href="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" />
    <link href="https://fonts.googleapis.com/css?family=Roboto+Condensed:300,300i,400,400i|Roboto:300,300i,400,400i" rel="stylesheet">
     <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
 <script src="Scripts/jquery-1.10.2.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>

        <!-- SPLIT NAVBARS -->
        <div class="collapse navbar-collapse" id="navbarsExampleDefault">
            <button type="button" class="btn" id="button-1"><a href="csr-lfg.html">CSR at LF</a></button>
            <button type="button" class="btn dropdown-toggle dropdown-toggle-split" id="button-1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                <span class="sr-only">Toggle Dropdown</span>
            </button>
            <div class="dropdown-menu">
                <a class="dropdown-item" href="#">Submenu Item 1</a>
                <a class="dropdown-item" href="#">Submenu Item 2</a>
                <div class="dropdown-divider"></div>
                <a class="dropdown-item" href="#">Submenu Item 3</a>
                <a class="dropdown-item" href="#">Submenu Item 4</a>
                <a class="dropdown-item" href="#">Submenu Item 5</a>
                <a class="dropdown-item" href="#">Submenu Item 6</a>
            </div>
        </div>
        </nav>