Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter Bootstrap 2, collapse-nav

Tags:

With Twitter Bootstrap 2, how do get links working within collapse-nav:

<div class="navbar navbar-fixed-top">
  <div class="navbar-inner">
    <div class="container">
      <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </a>
      <a class="brand" href="/index.html">Hubsphere - Controller</a>
      <div class="nav-collapse">
        <ul class="nav">
          <li class="">
            <a href="./index.html">Overview</a>
          </li>
        </ul>
      </div>
    </div>
  </div>
</div>    

i have jquery included, and the bootstrap-collapse.js file.

I have tried calling $('.nav-collapse').collapse() but this just opens the collapse area and dose not activate the button. which is what i expected as it should just work with markup.

thanks

like image 460
nodrog Avatar asked Feb 07 '12 16:02

nodrog


People also ask

How do I make bootstrap navbar collapse?

To create a collapsible navigation bar, use a button with class="navbar-toggler", data-toggle="collapse" and data-target="#thetarget" . Then wrap the navbar content (links, etc) inside a div element with class="collapse navbar-collapse" , followed by an id that matches the data-target of the button: "thetarget".

What is collapse navbar collapse in bootstrap?

Introduction to Bootstrap Collapse Navbar. Navigation bar (Navbar) is a header or index of the web application. It is always placed on top of the web page. The collapse in bootstrap is used for space-saving of large content. It is hidden and shows the content when the user wants.

How do I put two navbar collapse content in the same line?

Wrap both #nabar-mid-collapse and #navbar-rt-collapse in a div with class row-fluid , and apply class col-xs-4 (*or any respective . col class according to the width you need for each item *) to both of them. There is no row-fluid in Bootstrap 3.

What is navbar toggler in bootstrap?

Navbar Toggle Label Bootstrap Navbar component is designed for mobile first approach. Therefore, the navbar renders as collapsed on mobile devices. It can be toggled by a hamburger button. Unfortunately, hamburger icons are proved to be less efficient and not very usable. Navbar Toggle component extends the default .


2 Answers

I was a bit curious to see if this problem still occurs with bootstrap 2.0.4

In fact, it makes no sense to include both bootstrap.js and bootstrap-collapse.js since bootstrap.js includes bootstrap-collapse.js

only boostrap-collapse.js http://jsfiddle.net/baptme/YWUmb/6/

It works pefectly fine as expected.

both boostrap.js & boostrap-collapse.js: http://jsfiddle.net/baptme/YWUmb/5/

If you click on the collapse button for the first time, the div opens and closes immediately. (I think it's because the plugin is declared twice).

And then it works ok.

This issue is specific to the early version of twitter boostrap (2.0.0) but it has been dealt with or no longer occuring due to a change in the plugin structure.

like image 77
baptme Avatar answered Nov 03 '22 01:11

baptme


Ok so my problem was that i was including bootstrap.js and the bootstrap-collapse.js in the same file, i assumed that bootstrap.js was needed, and then when it did not work i included bootstrap-collapse.js.

It is now obvious to me, but bootstrap.js is all the bootstrap js rolled up. Which is nice...

like image 25
nodrog Avatar answered Nov 03 '22 01:11

nodrog