Solved

nav bar width

Posted on 2013-05-27
9
376 Views
Last Modified: 2013-05-31
Hi,
In Twitter bootstrap this navbar collapses or stacks when browser resizes to under 979px.
How do I get it to collapse under a different size like 500px or any other width?


  <div class='navbar navbar-inverse'>
      <div class='navbar-inner nav-collapse' style="height: auto;">
        <ul class="nav">
          <li class="active"><a href="#">Home</a></li>
          <li><a href="#">Page One</a></li>
          <li><a href="#">Page Two</a></li>
        </ul>
      </div>
    </div> 

Open in new window

0
Comment
Question by:jagguy
9 Comments
 
LVL 15

Expert Comment

by:Jagadishwor Dulal
ID: 39199138
0
 

Author Comment

by:jagguy
ID: 39199194
I dont need to know how to do a menu but how in bootstrap to set the width before objects collapse/stack?
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 39199444
do the width in percentage or vw and set min-width to 500px.

Cd&
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 10

Expert Comment

by:Ishaan Rawat
ID: 39199498
Try the following steps;;;

first locate the css where it is written  
@media (max-width: 979px)

Open in new window

in the bootstrap CSS....

Then make sure that it has ...only the navigation ids and classes... and one body tag....

If its true then modify the media query like the following....

@media (max-width: 500px) // Change that to your desired one.. 

Open in new window


If there's any problem contact us again... we'll be happy to help you...
0
 

Author Comment

by:jagguy
ID: 39199938
Ok i changed the media query and it works but there is so much other code I have changed as well that is the worry.

isnt it better I just add more css to override the specific css class/id instead of effecting everything else as there might be some unwanted side effects?

Placing my css file to override the boostrap css didnt work actually even when my css file is placed after the bootstrap css
bootstrap-responsive.css

/*@media (max-width: 979px) {    mychange*/
@media (max-width: 379px) { 
  body {
    padding-top: 0;
  }
  .navbar-fixed-top,
  .navbar-fixed-bottom {
    position: static;
  }
  .navbar-fixed-top {
    margin-bottom: 20px;
  }
  .navbar-fixed-bottom {
    margin-top: 20px;
  }
  .navbar-fixed-top .navbar-inner,
  .navbar-fixed-bottom .navbar-inner {
    padding: 5px;
  }
  .navbar .container {
    width: auto;
    padding: 0;
  }
  .navbar .brand {
    padding-right: 10px;
    padding-left: 10px;
    margin: 0 0 0 -5px;
  }
  .nav-collapse {
    clear: both;
  }
  .nav-collapse .nav {
    float: none;
    margin: 0 0 10px;
  }
  .nav-collapse .nav > li {
    float: none;
  }
  .nav-collapse .nav > li > a {
    margin-bottom: 2px;
  }
  .nav-collapse .nav > .divider-vertical {
    display: none;
  }
  .nav-collapse .nav .nav-header {
    color: #777777;
    text-shadow: none;
  }
  .nav-collapse .nav > li > a,
  .nav-collapse .dropdown-menu a {
    padding: 9px 15px;
    font-weight: bold;
    color: #777777;
    -webkit-border-radius: 3px;
       -moz-border-radius: 3px;
            border-radius: 3px;
  }
  .nav-collapse .btn {
    padding: 4px 10px 4px;
    font-weight: normal;
    -webkit-border-radius: 4px;
       -moz-border-radius: 4px;
            border-radius: 4px;
  }
  .nav-collapse .dropdown-menu li + li a {
    margin-bottom: 2px;
  }
  .nav-collapse .nav > li > a:hover,
  .nav-collapse .nav > li > a:focus,
  .nav-collapse .dropdown-menu a:hover,
  .nav-collapse .dropdown-menu a:focus {
    background-color: #f2f2f2;
  }
  .navbar-inverse .nav-collapse .nav > li > a,
  .navbar-inverse .nav-collapse .dropdown-menu a {
    color: #999999;
  }
  .navbar-inverse .nav-collapse .nav > li > a:hover,
  .navbar-inverse .nav-collapse .nav > li > a:focus,
  .navbar-inverse .nav-collapse .dropdown-menu a:hover,
  .navbar-inverse .nav-collapse .dropdown-menu a:focus {
    background-color: #111111;
  }
  .nav-collapse.in .btn-group {
    padding: 0;
    margin-top: 5px;
  }
  .nav-collapse .dropdown-menu {
    position: static;
    top: auto;
    left: auto;
    display: none;
    float: none;
    max-width: none;
    padding: 0;
    margin: 0 15px;
    background-color: transparent;
    border: none;
    -webkit-border-radius: 0;
       -moz-border-radius: 0;
            border-radius: 0;
    -webkit-box-shadow: none;
       -moz-box-shadow: none;
            box-shadow: none;
  }
  .nav-collapse .open > .dropdown-menu {
    display: block;
  }
  .nav-collapse .dropdown-menu:before,
  .nav-collapse .dropdown-menu:after {
    display: none;
  }
  .nav-collapse .dropdown-menu .divider {
    display: none;
  }
  .nav-collapse .nav > li > .dropdown-menu:before,
  .nav-collapse .nav > li > .dropdown-menu:after {
    display: none;
  }
  .nav-collapse .navbar-form,
  .nav-collapse .navbar-search {
    float: none;
    padding: 10px 15px;
    margin: 10px 0;
    border-top: 1px solid #f2f2f2;
    border-bottom: 1px solid #f2f2f2;
    -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 0 rgba(255, 255, 255, 0.1);
       -moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 0 rgba(255, 255, 255, 0.1);
            box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 0 rgba(255, 255, 255, 0.1);
  }
  .navbar-inverse .nav-collapse .navbar-form,
  .navbar-inverse .nav-collapse .navbar-search {
    border-top-color: #111111;
    border-bottom-color: #111111;
  }
  .navbar .nav-collapse .nav.pull-right {
    float: none;
    margin-left: 0;
  }
  .nav-collapse,
  .nav-collapse.collapse {
    height: 0;
    overflow: hidden;
  }
  .navbar .btn-navbar {
    display: block;
  }
  .navbar-static .navbar-inner {
    padding-right: 10px;
    padding-left: 10px;
  }
}

@media (min-width: 980px) {
  .nav-collapse.collapse {
    height: auto !important;
    overflow: visible !important;
  }
}

Open in new window

0
 
LVL 10

Expert Comment

by:Ishaan Rawat
ID: 39200306
There is a solution for this....

Just add !important to every single style of your code... That you have provided..

Wait I have done that for you...

@media (max-width: 379px) { 
  body {
    padding-top: 0 !important;
  }
  .navbar-fixed-top,
  .navbar-fixed-bottom {
    position: static !important;
  }
  .navbar-fixed-top {
    margin-bottom: 20px !important;
  }
  .navbar-fixed-bottom {
    margin-top: 20px !important;
  }
  .navbar-fixed-top .navbar-inner,
  .navbar-fixed-bottom .navbar-inner {
    padding: 5px !important;
  }
  .navbar .container {
    width: auto !important;
    padding: 0 !important;
  }
  .navbar .brand {
    padding-right: 10px !important;
    padding-left: 10px !important;
    margin: 0 0 0 -5px !important;
  }
  .nav-collapse {
    clear: both !important;
  }
  .nav-collapse .nav {
    float: none !important;
    margin: 0 0 10px !important;
  }
  .nav-collapse .nav > li {
    float: none !important;
  }
  .nav-collapse .nav > li > a {
    margin-bottom: 2px !important;
  }
  .nav-collapse .nav > .divider-vertical {
    display: none !important;
  }
  .nav-collapse .nav .nav-header {
    color: #777777 !important;
    text-shadow: none !important;
  }
  .nav-collapse .nav > li > a,
  .nav-collapse .dropdown-menu a {
    padding: 9px 15px !important;
    font-weight: bold !important;
    color: #777777 !important;
    -webkit-border-radius: 3px !important;
       -moz-border-radius: 3px !important;
            border-radius: 3px !important;
  }
  .nav-collapse .btn {
    padding: 4px 10px 4px !important;
    font-weight: normal !important;
    -webkit-border-radius: 4px !important;
       -moz-border-radius: 4px !important;
            border-radius: 4px !important;
  }
  .nav-collapse .dropdown-menu li + li a {
    margin-bottom: 2px !important;
  }
  .nav-collapse .nav > li > a:hover,
  .nav-collapse .nav > li > a:focus,
  .nav-collapse .dropdown-menu a:hover,
  .nav-collapse .dropdown-menu a:focus {
    background-color: #f2f2f2 !important;
  }
  .navbar-inverse .nav-collapse .nav > li > a,
  .navbar-inverse .nav-collapse .dropdown-menu a {
    color: #999999 !important;
  }
  .navbar-inverse .nav-collapse .nav > li > a:hover,
  .navbar-inverse .nav-collapse .nav > li > a:focus,
  .navbar-inverse .nav-collapse .dropdown-menu a:hover,
  .navbar-inverse .nav-collapse .dropdown-menu a:focus {
    background-color: #111111 !important;
  }
  .nav-collapse.in .btn-group {
    padding: 0 !important;
    margin-top: 5px !important;
  }
  .nav-collapse .dropdown-menu {
    position: static !important;
    top: auto !important;
    left: auto !important;
    display: none !important;
    float: none !important;
    max-width: none !important;
    padding: 0 !important;
    margin: 0 15px !important;
    background-color: transparent !important;
    border: none !important;
    -webkit-border-radius: 0 !important;
       -moz-border-radius: 0 !important;
            border-radius: 0 !important;
    -webkit-box-shadow: none !important;
       -moz-box-shadow: none !important;
            box-shadow: none !important;
  }
  .nav-collapse .open > .dropdown-menu {
    display: block !important;
  }
  .nav-collapse .dropdown-menu:before,
  .nav-collapse .dropdown-menu:after {
    display: none !important;
  }
  .nav-collapse .dropdown-menu .divider {
    display: none !important;
  }
  .nav-collapse .nav > li > .dropdown-menu:before,
  .nav-collapse .nav > li > .dropdown-menu:after {
    display: none !important;
  }
  .nav-collapse .navbar-form,
  .nav-collapse .navbar-search {
    float: none !important;
    padding: 10px 15px !important;
    margin: 10px 0 !important;
    border-top: 1px solid #f2f2f2 !important;
    border-bottom: 1px solid #f2f2f2 !important;
    -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 0 rgba(255, 255, 255, 0.1) !important;
       -moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 0 rgba(255, 255, 255, 0.1) !important;
            box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 0 rgba(255, 255, 255, 0.1) !important;
  }
  .navbar-inverse .nav-collapse .navbar-form,
  .navbar-inverse .nav-collapse .navbar-search {
    border-top-color: #111111 !important;
    border-bottom-color: #111111 !important;
  }
  .navbar .nav-collapse .nav.pull-right {
    float: none !important;
    margin-left: 0 !important;
  }
  .nav-collapse,
  .nav-collapse.collapse {
    height: 0 !important;
    overflow: hidden !important;
  }
  .navbar .btn-navbar {
    display: block !important;
  }
  .navbar-static .navbar-inner {
    padding-right: 10px !important;
    padding-left: 10px !important;
  }
}

Open in new window


and just make sure to remove the above code from the
@media (max-width: 979px)

Open in new window



This will surely work,,,
0
 

Author Comment

by:jagguy
ID: 39200928
no this doesnt work sorry.

if I have your code in a css file it doesnt override the bootstrap css as I just tied it. Anyway I am after a conventional solution so maybe I just need to alter bootstrap css and leave it as that.

if I have a problem then I can custom make a navigation my self and avoid navbar classes
0
 
LVL 10

Accepted Solution

by:
Ishaan Rawat earned 500 total points
ID: 39200947
Let me again tell you the steps...


First locate the navbar files in the bootstrap-responsive.css under the media queries... then cut them and paste then in the end of the bootstrap-responsive.css under the head
@media (max-width: 379px)

Open in new window

... If possible please give me a live url of the page...
0
 

Author Comment

by:jagguy
ID: 39210466
yes it works in the same file as you suggest.
it doesnt work when I place the same code in my own css and leave the orginal.
no matter as I dont intend to use the nav bar anyway.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question