Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change navbar collapse threshold using Twitter bootstrap-responsive?

I'm using Twitter Bootstrap 2.0.1 in a Rails 3.1.2 project, implemented with bootstrap-sass. I'm loading both the bootstrap.css and the bootstrap-responsive.css files, as well as the bootstrap-collapse.js Javascript.

I have a fluid layout with a navbar similar to the example. This follows the navbar "responsive variation" instructions here. It works fine: if the page is narrower than about 940px, the navbar collapses and displays a "button" that I can click on to expand.

However my navbar looks good down to about 550px wide, i.e. it doesn't need to be collapsed unless the screen is very narrow.

How do I tell Bootstrap to only collapse the navbar if the screen is less than 550px wide?

Note that at this point I do not want to modify the other responsive behaviors, e.g. stacking elements instead of displaying them side by side.

like image 789
Mark Berry Avatar asked Feb 23 '12 00:02

Mark Berry


People also ask

How do you collapse a collapsed navbar?

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".

How do you close an open collapsed navbar when clicking outside?

Currently, the only way to open or close it is by clicking on the navbar-toggle button.


1 Answers

Bootstrap > 2.1 && < 3

  • Use the less version of bootstrap
  • Change the @navbarCollapseWidth variable in variables.less
  • Recompile.

Update 2013: The easy way

  • Visit http://getbootstrap.com/customize/#less-variables
  • Change @navbarCollapseWidth in the formfield
  • Click "Compile and Download".

(THX to Archonic via comment)

Update 2014: Bootstrap 3.1.1 and 3.2 (they even added it to the documentation)

If you're customizing or overriding/editing .less variables, you're looking for:

//** Point at which the navbar becomes uncollapsed. @grid-float-breakpoint:     @screen-sm-min; //** Point at which the navbar begins collapsing. @grid-float-breakpoint-max: (@grid-float-breakpoint - 1); 
like image 55
Bijan Avatar answered Sep 30 '22 15:09

Bijan