Solved

nav bar width

Posted on 2013-05-27
9
375 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
 
LVL 9

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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 9

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 9

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

910 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now