I have a bootstrap navbar with a series of links displayed as nav-pills.
The pills display horizontally on mobile correctly however when the screen gets to above 768px they swap to a vertical layout which I do not want.
I suspect there is a media query somewhere that triggers # 768px however I am unsure of where.
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Title -->
<div class="navbar-header">
<!-- Required bootstrap placeholder for the collapsed menu -->
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
Dropdown
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li><i class="icon-home icon-2x"></i> Home<br>
</li>
<li><i class=" icon-pencil icon-2x"></i>About Us
</li>
<li><i class=" icon-briefcase icon-2x"></i>Portfolio
</li>
<li><i class=" icon-envelope icon-2x"></i>Contact Us
</li>
</ul>
</li>
<li>
<%= link_to search_path do %>
<i class="glyphicon glyphicon-search"></i><!-- Find -->
<% end %>
</li>
<li>
<a href="#" class="visible-xs visible-sm" data-toggle="collapse" data-target="#activity_parent">
<i class="fa fa-list"></i>
</a>
</li>
</ul>
</div>
</div><!-- /.container-fluid -->
</nav>
Edit
Ok, I found the following bootstrap media queries:
#media (min-width: 768px)
.navbar-nav {
float: left;
margin: 0;
}
#media (min-width: 768px)
.navbar-nav > li {
float: left;
}
I have changed the navbar menu items to "nav navbar-nav" from "nav nav-pills" and added the following css so that these setting remain even when the screen is less than 768px.
.navbar-nav {
float: left;
margin: 0;
}
.navbar-nav > li {
float: left;
}
Now the links are displayed horizontally regardless of screen size. I do now have a new related problem.
When the screen > 768px the dropdown looks correct:
When the screen < 768px the dropdown looks incorrect:
Try this, this may helps you.
#media (max-width: 767px){
.nav-pills>li {
float: none;
display: block;
}
}
For Demo
Here is the codepen demo link.
Related
Using bootstrap I have created a navbar using the bootstrap example online:
https://getbootstrap.com/docs/3.3/components/#navbar
My navbar includes a single dropdown menu which works well however on mobiles the navbar collapses into a dropdown menu which in turn contains my dropdown menu. i.e. a dropdown menu within a dropdown menu
Is it possible to have my downdown menu work normally however when the navbar collapses have the dropdown menu items listed as menu items in the collapsed menu not within a dropdown?
<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" 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="#">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 navbar-right">
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li role="separator" class="divider"></li>
<li>Separated link</li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
is this what you are looking for:jsfiddle
#media only screen and (max-width: 767px) {
.nav>li>a.dropdown-toggle {
display: none;
}
.nav .dropdown-menu {
display:block;
position: static;
float: none;
width: auto;
margin-top: 0;
background-color: transparent;
border: 0;
-webkit-box-shadow: none;
box-shadow: none;
}
}
updated version: jsfiddle.net
I'm a bit late to the party but I was reading this looking for a way to "uncollapse" the dropdown menu on a mobile device. The css
Nikola Kostov gave (below) is great, there is just one issue with it. The responsive breakpoint for bootstrap is at 768px, the official documentation at https://v4-alpha.getbootstrap.com/layout/overview/ states:-
// Medium devices (tablets, 768px and up)
#media (min-width: 768px)
So for everything smaller than that you need to use
#media only screen and (max-width: 767px) {
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/
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
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/
I have a little problem, i got bootstrap navbar set up, but when i resize it to the tablet width, menu escapes the navbar and gets into content like shown here:
http://oi57.tinypic.com/2uykv9g.jpg "see the problem"
Is the menu too wide ? Any help how to fix this would be greatly appriciated.
Code here:
<div class="navbar navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="fa fa-bars color-white"></span>
</button>
<a class="navbar-brand" href="index.html" ><img class="img-responsive" src="images/new.jpg"></a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav" >
<li class="active"><i class="fa fa-home"></i></li>
<li>Packages</li>
<li>Examples of webpages</li>
<li>Our Services</li>
<li>Benefits</li>
<li>References</li>
<li>Contact </li>
</ul>
</div><!--/.navbar-collapse -->
</div>
</div>
Ok i fixed it, so in case somebody else is having that problem, all i did was scale down the logo (which was partially the problem) to 80% on devices smaller than 992px, gave it an absolute positioning etc, here is the css:
#navbar-height: 150px;
#navbar-brand-vpadding: 10px;
.navbar-brand img {
height: #navbar-height - #navbar-brand-vpadding * 2;
position: absolute;
top: #navbar-brand-vpadding;
}
#media (max-width: 992px) {
.make-custom-class-here {
width:201px;
height:41px;
}
}