This is my simple navbar:
<div class="navbar navbar-fixed-top myfont" role="navigation"> <div class=""> <ul class="nav navbar-nav navbar-left"> <li> <a class="navbar-brand" href="#"> <img src="assets/img/logo.png"/> </a> </li> <li> <button class="btn btn-navbar"> <i class="fa fa-edit"></i> Create </button> </li> </ul> </div> <ul class="nav navbar-nav navbar-right"> <li data-match-route="/"><a href="#/page-one">Login</a></li> <li data-match-route="/"><a href="#/page-two/sub-a">Signup</a></li> </ul> </div>
I just would like to prevent this to collapse, cause I don't need it, how to do?
I would like to avoid writing 300K lines of CSS for overriding the default styles.
Any suggestion?
For navbars that never collapse, add the . navbar-expand class on the navbar. For navbars that always collapse, don't add any . navbar-expand class.
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".
Currently, the only way to open or close it is by clicking on the navbar-toggle button.
After close examining, not 300k lines but there are around 3-4 CSS properties that you need to override:
.navbar-collapse.collapse { display: block!important; } .navbar-nav>li, .navbar-nav { float: left !important; } .navbar-nav.navbar-right:last-child { margin-right: -15px !important; } .navbar-right { float: right!important; }
And with this your menu won't collapse.
DEMO (jsfiddle)
EXPLANATION
The four CSS properties do the respective:
The default .collapse
property in bootstrap hides the right-side of the menu for tablets(landscape) and phones and instead a toggle button is displayed to hide/show it. Thus this property overrides the default and persistently shows those elements.
For the right-side menu to appear on the same line along with the left-side, we need the left-side to be floating left.
This property is present by default in bootstrap but not on tablet(portrait) to phone resolution. You can skip this one, it's likely to not affect your overall navbar.
This keeps the right-side menu to the right while the inner elements (li
) will follow the property 2. So we have left-side float left and right-side float right which brings them into one line.
The nabvar will collapse on small devices. The point of collapsing is defined by @grid-float-breakpoint
in variables. By default this will by before 768px
. For screens below the 768
pixels screen width, the navbar will look like:
It's possible to change the @grid-float-breakpoint
in variables.less and recompile Bootstrap. When doing this you also will have to change @screen-xs-max
in navbar.less. You will have to set this value to your new @grid-float-breakpoint -1
. See also: https://github.com/twbs/bootstrap/pull/10465. This is needed to change navbar forms and dropdowns at the @grid-float-breakpoint to their mobile version too.
Easiest way is to customize bootstrap
find variable:
@grid-float-breakpoint
which is set to @screen-sm
, you can change it according to your needs. Hope it helps!
add your custom variables like $grid-float-breakpoint: 0px;
before the @import "bootstrap.scss";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With