简体   繁体   English

导航栏切换按钮不显示折叠的元素

[英]Navbar-toggle Button doesn't show collapsed elements

I'm currently trying to create a button that will reveal me the collapsed navigation links when the screen gets too small. 我目前正在尝试创建一个按钮,当屏幕过小时,该按钮将向我显示折叠的导航链接。 The button does materialize, but I can't get it to perform anything besides appearing when the screen gets small. 该按钮确实实现了,但是除了屏幕变小之外,我无法执行其他任何操作。

The toggle button also creates small '>' arrows when I only intended to have the white "-" lines in the button. 当我仅打算在按钮中使用白色的“-”线时,切换按钮还会创建小的“>”箭头。

I realized that jquery and bootstrap's js files should be included at the bottom of the body tag, but so far I've had no luck even with those added. 我意识到jquery和bootstrap的js文件应该包含在body标签的底部,但是到目前为止,即使添加了这些,我也没有运气。 Any help is appreciated. 任何帮助表示赞赏。

https://codepen.io/Tintinator/pen/NvKRvO https://codepen.io/Tintinator/pen/NvKRvO

<div class="navbar navbar-default navbar-static-top navbar-inverse">

  <div class="container">

    <!-- BRAND, BUTTON -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-
      toggle="collapse" data-target=".navbar-nav">
        <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="navbar-brand" href="#">
        <img src="./newnewfoy.png">
      </a>
    </div>

    <!-- NAV LINKS -->
    <div class="navbar-collapse collapse">
      <ul class="nav navbar-nav" id="navilinks">
        <li class="nav-item">
          <a class="nav-link active" href="#">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">About</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Event</a>
        </li>
        <li class="nav-item">
          <a class="nav-link disabled" href="#">Volunteer</a>
        </li>
        <li class="nav-item">
          <a class="nav-link disabled" href="#">Sponsors</a>
        </li>
        <li class="nav-item">
          <a class="nav-link disabled" href="#">Contact</a>
        </li>
      </ul>
      <div class="medialinks hidden-sm hidden-xs">
        <a id="YOUcon" class = "mediacon" href="www.google.com"></a>
        <a id="IGcon" class = "mediacon" href="www.google.com"></a>
        <a id="TWTcon" class = "mediacon" href="www.google.com"></a>
        <a id="FBcon"  class="mediacon" href="www.google.com"></a>
      </div>
    </div>

  </div>

</div>

You have wrong data-target attribute and a css rule that limits nav height (50px) which doesn't let it to expand properly. 您有错误的data-target属性和css规则,该规则限制了导航高度(50像素),而该高度无法使其正常扩展。 And I believe parent element should be nav not div. 而且我相信父元素应该是nav而不是div。

Try this instead: 尝试以下方法:

<!-- NAVIGATION BAR -->
<nav class="navbar navbar-default navbar-static-top navbar-inverse">

  <div class="container">

    <!-- BRAND, BUTTON -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navilinks" 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="navbar-brand" href="#">
        <img src="./newnewfoy.png">
      </a>
    </div>

    <!-- NAV LINKS -->
    <div class="navbar-collapse collapse" id="navilinks">
      <ul class="nav navbar-nav" >
        <li class="nav-item">
          <a class="nav-link active" href="#">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">About</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Event</a>
        </li>
        <li class="nav-item">
          <a class="nav-link disabled" href="#">Volunteer</a>
        </li>
        <li class="nav-item">
          <a class="nav-link disabled" href="#">Sponsors</a>
        </li>
        <li class="nav-item">
          <a class="nav-link disabled" href="#">Contact</a>
        </li>
      </ul>
      <div class="medialinks hidden-sm hidden-xs">
        <a id="YOUcon" class = "mediacon" href="www.google.com"></a>
        <a id="IGcon" class = "mediacon" href="www.google.com"></a>
        <a id="TWTcon" class = "mediacon" href="www.google.com"></a>
        <a id="FBcon"  class="mediacon" href="www.google.com"></a>
      </div>
    </div>

  </div>

</nav>

https://codepen.io/anon/pen/oevYvp https://codepen.io/anon/pen/oevYvp

I'm not sure if this is is, but did you add the plugin? 我不确定是否是,但是您是否添加了插件? (see image) (见图片)

引导插件信息

Within your codepen, I modified a couple lines of code and it seems to do the trick. 在您的Codepen中,我修改了几行代码,似乎可以解决问题。 I changed the data-target from a class to an id of #navbar and then updated the initial div in your "NAV LINKS" to include the id of #navbar. 我将数据目标从类更改为#navbar的ID,然后将“ NAV LINKS”中的初始div更新为包含#navbar的ID。 I forked your codepen for you. 我为您分叉了Codepen。 https://codepen.io/ckroll17/pen/qXWqbV https://codepen.io/ckroll17/pen/qXWqbV

<!--           
      Changed button to data-target to #navbar
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-nav"> -->
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar">
            <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="navbar-brand" href="#">
            <img src="./newnewfoy.png">
          </a>
        </div>

        <!-- NAV LINKS -->
        <!-- Added an id of navbar to the class directly below -->
        <div id="navbar" class="navbar-collapse collapse">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM