Problems with the responsive navbar in Bootstrap 3

后端 未结 7 1881
我在风中等你
我在风中等你 2021-02-01 18:10

I had no problem with the responsive navbar in the last version of Bootstrap, but I cannot get version 3 to work. The toggle button appears properly and everything disappears bu

相关标签:
7条回答
  • 2021-02-01 18:18

    Change this: .navbar-responsive-collapse

    to this: .navbar-collapse

    Original poster solved his own question. Posting a more concise version here as this helped me. PhilNicholas' version did not work.

    0 讨论(0)
  • 2021-02-01 18:22

    This worked for me: I changed .navbar-ex1-collapse to .navbar-collapse.

    0 讨论(0)
  • 2021-02-01 18:23

    I am using Bootstrap 3.2.0. What fixed this problem for me was changing the version of jQuery I was using. Apparently, jQuery 1.7.1 is not compatible with the latest bootstrap. After switching to jQuery 2.0.2, all was well:

    <script type='text/javascript' src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
    
    0 讨论(0)
  • 2021-02-01 18:28

    I believe the code below will produce the effect you're looking for. Specifically, there is no "navbar-responsive-collapse" class in BS3 (see the "bootstrap.css" file). Beginning with release 3 Twitter Bootstrap is responsive by default, so many of the code flags for responsiveness are now baked into the framework and no longer need to be called explicitly.

    Here's a BS3 version of the right-aligned collapsible menu:

    <div class="navbar navbar-default navbar-fixed-top" role="navigation">
    <div class="navbar-header">
    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
    </button>
    <a href= "#" class="navbar-brand">Brand Name</a>
    </div>
    <div class="collapse navbar-collapse navbar-ex1-collapse">
        <ul class="nav navbar-nav pull-right">
            <li class="active "><a href="#">Home</a></li>
            <li><a href="#">Link 1</a></li>
            <li><a href="#">Link 2</a></li>
            <li><a href="#">Link 3</a></li>
            <li><a href="#">Link 4</a></li>
        </ul>   
    </div>
    </div>
    
    0 讨论(0)
  • 2021-02-01 18:32

    Twitter bootstrap uses the bundled Collapse jquery plugin to toggle the navigation menu on mobile screen form factors. Your question pertains to a slightly old release of bootstrap but still remains relevant – the toggle can be triggered on an element by setting:

    data-toggle="collapse" and data-target="#valid_css_selector_of_target_element".

    The catch here is the latter – as far as the functioning of Collapse plugin is concerned it doesn't matter whether you have a predefined bootstrap class .navbar-responsive-collapse, the only thing that matters here is that element exists in your html. The existence of a bootstrap class however would very likely affect how it's styled.

    The bootstrap documentation at the time of this writing (and I believe since long) shows, via an example, the use of an id attribute to select the target element; which I find a bit better because there can be more than one elements with the same class on the same page, while Ids are unique in an html document. So, in your case:

    <div class="collapse navbar-collapse navbar-ex1-collapse"> would look something like <div class="collapse navbar-collapse navbar-ex1-collapse" id="my_nav"> and the toggle button would have an attribute data-target="#my_nav".

    0 讨论(0)
  • 2021-02-01 18:34

    Bootstrap 3 requires jquery.

    --> Best practice to put your scripts at the end too.

    <script src="//code.jquery.com/jquery-1.10.2.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    

    0 讨论(0)
提交回复
热议问题