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.
Bootstrap 3.x
using LESS, you can change the value of
@screen-small
to target your min sizeexample:
@screen-small: 600px;
i use this to only switch to "tiny device" mode once the width is less than 600px
This is a great example of where you could be using the LESS version of the Bootstrap CSS files. How to do this is below.
Even better would be to submit this as a pull request on Github so that everyone can benefit and your "custom code" would hopefully be part of Bootstrap moving forward.
variables.less
that specifies when to collapse the navbar. Something like:@navCollapseWidth: 979px
responsive-navbar.less
...@media (max-width: 979px)
to@media (max-width: @navCollapseWidth)
@media (min-width: 980px)
to@media (max-width: @navCollapseWidth - 1)
Of course... you'd have to compile LESS using one of the suggested methods.
Taking tyler's hack even further by adding a visible-phone classed block and a hidden-phone class to an item in the main collapsible navigation, you can 'pull out' one or two of the collapsed items to display even in the phone navbar.
I suspect (and hope) this will be implemented in an official way soon. In the meantime I'm just doing a simple css hack, using visible-phone on the dropdown button and visible-tablet on a second set of buttons I've placed in the navbar. So before it looked like this:
And now it looks like:
Note that order of elements is important, otherwise you may have issues with elements going into the next line
You can establish a new
@media
query to drop the navbar elements down as you see fit, all you have to do is reset the former to accommodate your new query with the desired drop width. Take this for example:CSS
In the following code you can see how I included the original
@media
query that handles the drop before the979px
mark and the new query to support your desired drop point of550px
. I modified the original query straight from the bootstrap-responsive css to reset all the styles applied to that specific query for the navbar elements and ported them to the new query that carries the drop point you need instead. This way we can commute all the styles from the original query down to the new query without messing around in the bootstrap-responsive stylesheet, this way the default values will still apply to the other elements in your document.Here is a short demo with a media query set to drop at
550px
as you require: http://jsfiddle.net/wU8MW/Note: I placed the above modified
@media
queries way down below the css frame as the new modified css is supposed to be loaded first than the responsive css.Here is my code (All other solution showed funky scrollbar as the navbar dropped down so I edited the code so it didn't). I could not post on other answer so I'll do it here for others to find. I am using rails to do this with Bootstrap 3.0.
assets/stylesheets/framework and overrides paste this: (Adjust max width to whatever value to achieve your goal.)