How to make bootstrap 3 navbar not wrap - css

I have a bootstrap 3 navbar.
JSFiddle
<div class="navbar navbar-inverse no-print">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/portal/home/index/">Logo of Site</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>Home</li>
<li class="dropdown">
My Menu Processes<span class="caret"></span>
</li>
<li class="dropdown">
Enquiries<span class="caret"></span>
</li>
<li class="dropdown">
Admin Reports <span class="caret"></span>
</li>
<li class="dropdown">
System Maintenance<span class="caret"></span>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a>Change password</a>
</li>
<li>
Welcome Firstname Lastname
</li>
<li>
Log Out
</li>
</ul>
</div>
</div>
When the width of the window is full desktop size it is correct.
When the width of the window is smaller mobile phone size it correct.
In between these two sizes it wraps this menu as well as doubling the menu's height which I don't want.
I think my only option is probably to increase the mobile width to increase with inbetween widths so the navbar shows in mobile mode in the screenshot.
What css do I need to achieve this?
How do I force the right navbar <ul> to not be allowed to move below the left navbar <ul>?

Try this...
#media (max-width: 1230px) {
.navbar-header {
float: none;
}
.navbar-left,.navbar-right {
float: none !important;
}
.navbar-toggle {
display: block;
}
.navbar-collapse {
border-top: 1px solid transparent;
box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
}
.navbar-fixed-top {
top: 0;
border-width: 0 0 1px;
}
.navbar-collapse.collapse {
display: none!important;
}
.navbar-nav {
float: none!important;
margin-top: 7.5px;
}
.navbar-nav>li {
float: none;
}
.navbar-nav>li>a {
padding-top: 10px;
padding-bottom: 10px;
}
.collapse.in{
display:block !important;
}
}
From: http://www.bootply.com/120951

By default, the navbar toggles and becomes accessible via the burger menu at viewports <= 767px...
Your best bet (something I do all the time with BS!) is to make is collapse at larger viewports. You can do this with this handy snippet of code.
#media (min-width: 768px) and (max-width: 991px) { /* You can change the max-width to whatever you want... */
.parent-class .navbar-collapse.collapse {
display: none;
}
.parent-class .navbar-collapse.collapse.in {
display: block;
}
.parent-class .navbar-header .collapse, .navbar-toggle {
display:block;
}
.parent-class .navbar-header {
float:none;
}
}
The above is a modified version of another answer on SO from some time ago - I can't find the link to it (I have this snippet lurking on my PC as I use it often).
You'll notice I've prepended .parent-class to the selectors above, this is to ensure these styles override the default BootStrap styles which don't normally get overridden till 767px and below...

<ul> is a block level element
you can use all li items in single <ul>
<ul class="nav navbar-nav">
<li>Home</li>
<li class="dropdown">
My Menu Processes<span class="caret"></span>
</li>
<li class="dropdown">
Enquiries<span class="caret"></span>
</li>
<li class="dropdown">
Admin Reports <span class="caret"></span>
</li>
<li class="dropdown">
System Maintenance<span class="caret"></span>
</li>
<li>
<a>Change password</a>
</li>
<li>
Welcome Firstname Lastname
</li>
<li>
Log Out
</li>
</ul>
Or you can align right and left align both <ul> and set tab view to set 12 columns each so both <ul> look better in tab view
mostly password login etc goes to top bar in a separate div.......so it will not break menu alignment

Related

navbar dropdown menus display issue on mobile and small devices with media query

Not a big expert in CSS and responsiveness design, I try to collapse my navbar using a media query. The issue is that for dropdown menus, the responsive design is not applied correctl : The dropdown menus are displayed like on a large desktop device.
What I want is this :
Result Expected
But the result I obtain is this :
Current result
My code is actually the following :
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> <span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button> <a class="navbar-brand" href="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active">Link <span class="sr-only">(current)</span>
</li>
<li>Link
</li>
<li class="dropdown"> Dropdown <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Action
</li>
<li>Another action
</li>
<li>Something else here
</li>
<li class="divider"></li>
<li>Separated link
</li>
<li class="divider"></li>
<li>One more separated link
</li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<ul class="nav navbar-nav navbar-right">
<li>Link
</li>
<li class="dropdown"> Dropdown <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Action
</li>
<li>Another action
</li>
<li>Something else here
</li>
<li class="divider"></li>
<li>Separated link
</li>
</ul>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
And my media query is the current one as I found googling the web :
#media (max-width: 992px) {
.navbar-header {
float: none;
}
.navbar-left,.navbar-right {
float: none !important;
}
.navbar-toggle {
display: block;
}
.navbar-collapse {
border-top: 1px solid transparent;
box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
}
.navbar-fixed-top {
top: 0;
border-width: 0 0 1px;
}
.navbar-collapse.collapse {
display: none!important;
}
.navbar-nav {
float: none!important;
margin-top: 7.5px;
}
.navbar-nav>li {
float: none;
}
.navbar-nav>li>a {
padding-top: 10px;
padding-bottom: 10px;
}
.collapse.in{
display:block !important;
}
}
Additional info : The menu is displayed well when the viewport size is under 768px.
I guess, there is something missing on my media query for handling the dropdown menu case but I don't know what it is ? Can somebody help me ?
Thanks a lot.
here is your fiddle just remove default style dropdown
jsfiddle.net/qxgy6L9b/18/

Bootstrap 3 nav bar colapse not working correctly

I want to change the break point at which the bootstrap collapses. I found some great answers on stack however they seem to not work correctly on my nav bar
Here is how my navbar looks like:
Now I have this extra CSS for my nav bar to colapse when the width of the screen reaches 991px
#media (max-width: 991px) {
.navbar-header {
float: none;
}
.navbar-toggle {
display: block;
}
.navbar-collapse {
border-top: 1px solid transparent;
box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
}
.navbar-collapse.collapse {
display: none!important;
}
.navbar-nav {
float: none!important;
margin: 7.5px -15px;
}
.navbar-nav>li {
float: none;
}
.navbar-nav>li>a {
padding-top: 10px;
padding-bottom: 10px;
}
.navbar-text {
float: none;
margin: 15px 0;
}
/* since 3.1.0 */
.navbar-collapse.collapse.in {
display: block!important;
}
.collapsing {
overflow: hidden!important;
}
}
When I resize my browser this i what happens: (see the red arrow for my problem).
Some of the links go out of the navigation bar. I would like it to work exactly the same as it works when I make the screen smaller and the original Bootstrap code kicks in for mobile devices (it just adds a scroll bar in nav bar and all menu elements are inside the navbar.
This is how it looks like when I make the screen smaller and original bootstrap code kicks in:
Here is the html code for my nav bar:
<nav class="navbar navbar-inverse navbar-fixed-top yellow_border_navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li>
<img src="images/SingleLogo.png" height="64">
</li>
<li class="dropdown navigation_link_margin">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Home
<span class="caret"></span></a>
<ul class="dropdown-menu">
<li>Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</li>
<?php if(isset($_SESSION['id'])){?>
<li class="navigation_link_margin">Profile</li>
<?php } ?>
<li class="navigation_link_margin">Clubs</li>
<li class="navigation_link_margin">Tournaments</li>
<li class="navigation_link_margin">Leaderboard</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<?php if(!isset($_SESSION['id'])){?>
<li><span class="glyphicon glyphicon-user"></span> Register</li>
<li><span class="glyphicon glyphicon-log-in"></span> Login</li>
<?php } else { ?>
<li><?php navigation_display_new_messages(); ?></li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#"><?php echo navigation_get_first_name(); ?>
<span class="caret"></span></a>
<ul class="dropdown-menu">
<?php side_menu_display(); ?>
<li><span class="glyphicon glyphicon-user"></span> Account</li>
<li><span class="glyphicon glyphicon-asterisk"></span> Credits</li>
<li><span class="glyphicon glyphicon-record"></span> Log Out</li>
</ul>
</li>
<?php } ?>
</ul>
</div>
</div>
</nav>
The max-height set by Bootstrap is clipping the mobile navbar. You can override like this...
.collapse.in{
display:block !important;
max-height: initial;
}
http://www.bootply.com/jv5TNZF9KM
By default, Bootstrap break point for small devices is 768px.
Assuming you have the bootstrap.css file (not the minified version), you can directly change the break point inside that file by changing the according 768px values to 991px.
However a more easy solution would be to override it by the following generic code, but it's not the cleanest nor efficient way to do it :
#media (max-width: 991px) {
.navbar-header {
float: none;
}
.navbar-left,.navbar-right {
float: none !important;
}
.navbar-toggle {
display: block;
}
.navbar-collapse {
border-top: 1px solid transparent;
box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
}
.navbar-fixed-top {
top: 0;
border-width: 0 0 1px;
}
.navbar-collapse.collapse {
display: none!important;
}
.navbar-nav {
float: none!important;
margin-top: 7.5px;
}
.navbar-nav>li {
float: none;
}
.navbar-nav>li>a {
padding-top: 10px;
padding-bottom: 10px;
}
.collapse.in{
display:block !important;
}
}
Also you should use the "navbar-brand" class for your logo and place it right after the hamburger menu button :
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.php">
<img src="iimages/SingleLogo.png" alt="">
</a>

Dynamically adaptive navbar examples

Did you know any examples of Use, or any code examples of adaptive navigation, which hide menu elements depend of screen width?
Please give some links to examples or working websites with this type of responsive nav
Solve it!
HTML code:
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">NOSTROMO inc.</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="menu-item active">Антропоморфоз</li>
<li class="menu-item">Филогенез</li>
<li class="menu-item">Адаптагенность</li>
<li class="menu-item">Абберация</li>
<li class="menu-item">Суперпозиция</li>
<li class="menu-item">Микрофиламент</li>
<li class="menu-item">Квинтесенция</li>
<li class="menu-item">Нейропластичность</li>
<li class="dropdown" id="menu-colapsed">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<span class="glyphicon glyphicon-option-horizontal"></span>
</a>
<ul class="dropdown-menu">
<li class="collapsed-menu-item">Антропоморфоз</li>
<li class="collapsed-menu-item">Филогенез</li>
<li class="collapsed-menu-item">Адаптагенность</li>
<li class="collapsed-menu-item">Абберация</li>
<li class="collapsed-menu-item">Суперпозиция</li>
<li class="collapsed-menu-item">Микрофиламент</li>
<li class="collapsed-menu-item">Квинтесенция</li>
<li class="collapsed-menu-item">Нейропластичность</li>
</ul>
</li>
</li>
</div>
</div>
</nav>
CSS code:
.collapsed-menu-item {
display: none;
}
/*hide menu items on resize and show dropdown "more" menu and add nenu items to dropdown*/
#media (max-width: 1500px) {
.menu-item:nth-child(n+8) {display: none}
.collapsed-menu-item:nth-child(n+8) {display: block}
}
#media (max-width: 1300px) {
.menu-item:nth-child(n+7) {display: none}
.collapsed-menu-item:nth-child(n+7) {display: block}
}
#media (max-width: 1100px) {
.menu-item:nth-child(n+6) {display: none}
.collapsed-menu-item:nth-child(n+6) {display: block}
}
#media (max-width: 1000px) {
.menu-item:nth-child(n+5) {display: none}
.collapsed-menu-item:nth-child(n+4) {display: block}
}
/*show all menu elements in mobile view and hide dropdown menu "more"*/
#media (max-width: 768px) {
.menu-item {
display: block !important;
}
#menu-colapsed {
display: none;
}
}
#media (min-width: 1500px) {
#menu-colapsed {
display: none;
}
}
live demo on codepen: http://codepen.io/DmitriySatinaev/pen/adYLad - resize window to see changes
Twitter's Bootstrap framework has a nice responsive navbar that collapses down to a hamburger icon when there is not enough screen width to show all the menu items.
https://getbootstrap.com/examples/navbar-static-top/
To change the color/style of them requires a bit of knowledge on how the bootstrap framework works and is not so newbie friendly, but luckily there is a fantastic generator which you can use to generate custom basic styling of Bootstrap's navbar at http://twitterbootstrap3navbars.w3masters.nl/

bootstrap menu with click and reveal drop down for screen sizes 768 px and 1099

i am using bootstrap for a drop down menu, and currently if screen sizes is more than 768 px; the drop down occurs when you hover mouse and if it goes below 768PX dropdown occurs when you click the menu item. its perfect.
But i want that from screen-size 768-1099px, it should be not hovering. It should be clicked and drop menu should appear as mobile version.
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse"
data-target="#example-navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">TutorialsPoint</a>
</div>
<div class="collapse navbar-collapse" id="example-navbar-collapse">
<ul class="nav navbar-nav">
<li class="active">iOS</li>
<li>SVN</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
Java <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li>jmeter</li>
<li>EJB</li>
<li>Jasper Report</li>
<li class="divider"></li>
<li>Separated link</li>
<li class="divider"></li>
<li>One more separated link</li>
</ul>
</li>
</ul>
</div>
</nav>
You can do this easily: http://www.bootply.com/114896
Just wrap that CSS in whatever sized media query you want to target, for example:
#media (min-width: 992px) and (max-width: 1099px) {
.navbar-header {
float: none;
}
.navbar-toggle {
display: block;
}
.navbar-collapse {
border-top: 1px solid transparent;
box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
}
.navbar-collapse.collapse {
display: none!important;
}
.navbar-nav {
float: none!important;
margin: 7.5px -15px;
}
.navbar-nav>li {
float: none;
}
.navbar-nav>li>a {
padding-top: 10px;
padding-bottom: 10px;
}
}
Thanks

Bootstrap navbar-fixed-top breaks when increasing height

So I have a navbar-fixed-top that's set to collapse at 992px, most mobile screens wont collapse at anything lower than that anymore. Well, from what I can tell anyway. The problem is that when I try increase the navbar height at the lower screen width, I cant vertically center anything on the navbar - being the placeholder for the logo to come or the dropdown button. I'm also struggling to increase the size of the dropdown button no matter what I try. Finally as soon as I increase the height of the navbar, when I click the dropdown menu, the background image disappears yet it works fine with the default height. I'm really hoping someone knows a trick or two as it seems lots of people are struggling with navbar-fixed-top.
Here's the html setup:
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#">Logo</a>
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#collapsed-navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse" id="collapsed-navbar">
<ul class="nav navbar-nav">
<li><a ng-href="#link">Link 1</a></li>
<li><a ng-href="#link">Link 2</a></li>
<li><a ng-href="#link">Link 3</a></li>
<li><a ng-href="#link">Link 4</a></li>
<li class="divider"></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><img class="img-circle nav-profile-image" src="images/default_pic.png" /></li>
<li><a ng-href="#link">Profile</a></li>
<li>Logout</li>
</ul>
</div>
</div>
</nav>
And here's the CSS so far:
#media (max-width: 992px) {
.nav-profile-image {
display: none;
}
.navbar {
height: 80px;
font-size: 24px;
}
}
#media (min-width: 992px) {
.nav-profile-image {
height: 40px;
margin-top: 5px;
}
}
.navbar {
background-image: url('../images/noise-background.jpg');
background-color: #F8F8F8;
}
.navbar-default .navbar-nav > li > a:hover {
color: #555;
background-color: #E7E7E7;
opacity: 0.6;
}
.navbar-default .navbar-nav > .active > a:hover {
color: #555;
background-color: #E7E7E7;
opacity: 1;
}
Thanks in advance!

Resources