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) {
Related
I've used Bootstrap 3.3.7 in my web design. It's working fine with Mobile, Desktop or Laptop. But for a tablet, I can't see three bar menu. If we take bootstrap default navbar,
<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">
<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">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li role="separator" class="divider"></li>
<li>Separated link</li>
<li role="separator" class="divider"></li>
<li>One more separated link</li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
It doesn't work for a tablet device. This is not only mine, you can see in Bootstrap website. When you browse on a tablet, you will notice that. Is it intentionally left or else something.
I would be very much thankful for your suggestion. I guess it will help for other who get such issue.
Thanks.
You can add some CSS rules if you want to see three bar menu on tablets. Bootstrap shows that menu for <768px.
#media (max-width: 1023px) { //1024 px for laptop
.navbar-header {
float: none;
}
.navbar-toggle {
display: block;
}
.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;
}
.collapse.in{
display:block !important;
}
}
For the last 4 hours i am trying to get an image scaled when the browser resizes. The website uses bootstrap and the image is situated in the navbar-brand part. I know the navbar-brand part is normally used for a logo, but in this situation there is a bunch of text under the logo which is part of the image.
Now what i like to accomplish is to scale this image when the browser resizes. I have tried a bunch of different css option without any success.
My latest:
.navbar-brand {
max-height: 500px;
}
.navbar-brand img
{
max-height: 100%;
height: auto;
width: auto;
}
I could use some fresh input ?
As you mentioned in comments, the image will take certain percentage (31% in your case) of the navbar width. You can set width as percentage to div.navbar-header which is the wrapper of img.navbar-brand. Media query is added to make the added style compliance with Bootstrap navbar responsive rules.
#media (min-width: 768px) {
.container-fluid>.navbar-header,
.container>.navbar-header {
width: 31%; /*31% as you mentioned in comments*/
}
img.navbar-brand {
width: auto;
height: auto;
max-height: 500px;
max-width: 100%;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<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>
<img src="https://www.codeproject.com/KB/GDI-plus/ImageProcessing2/flip.jpg" class="navbar-brand">
</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">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li role="separator" class="divider"></li>
<li>Separated link</li>
<li role="separator" class="divider"></li>
<li>One more separated link</li>
</ul>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
I am using the Bootstrap navbar-fixed-top method to create a floating nav bar.
I have a few issues I cannot figure out:
Why are my logo and my social icons disappearing when I reduce screen-width to 769px?
Why is my logo and social icons right at the top of the page?
My social icons are too small and bunched up next to each other. How do I change this?
http://codepen.io/dhruvghulati/pen/qrdNBm
What should I do to have a persistent nav bar which is more standard?
.collapse class looks like this:
.collapse {
display: none;
visibility: hidden;
}
And there is:
#media (min-width: 768px)
.navbar-collapse.collapse {
display: block!important;
height: auto!important;
padding-bottom: 0;
overflow: visible!important;
visibility: visible!important;
}
Which means .collapse will be not displayed until screen is 768px width.
Also there is (used for logo):
#media (min-width: 768px)
.navbar-left {
float: left!important;
}
That makes logo float left since screen is 768px width, there is similar class for .navbar-right which is used for social icons container.
You should probably visit the official Bootstrap docs to get more information on navbars. I would use this as the template for your navbar and go from there:
<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">
<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">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li role="separator" class="divider"></li>
<li>Separated link</li>
<li role="separator" class="divider"></li>
<li>One more separated link</li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-left">
<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">
<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 -->
Essentially, Bootstrap replaces your nav link with a hamburger button at that screen size. Also, you should give the logo the proper classes (from the code above) to make sure it's always visible. To make the navbar stick to the top of the page, simply add the navbar-fixed-top class to the nav tag. the opening tag should now look like this: <nav class="navbar navbar-default navbar-fixed-top">.
I think its because you are using position:absolute; try using position: relative; instead
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 bootstrap header nav bar with buttons. What I trying to do is to add button which is visible only on mobile devices and small screens - phones/tablets.
This is structure of the header
<header>
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" 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>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav" >
<li>Button 1</li>
<li>Button 2</li>
<li>Button 3</li>
<li>BUTTON 4</li>
</ul>
</div>
</nav>
</header>
I want to make BUTTON 4 visible only on small screens.
So I make the button like this:
<li class="not_visible">BUTTON 4</li>
Then in css I add
.not_visible {
display: none;
}
#media (max-width: 767px) {
.header{
text-align : center;
}
.not_visible {
display: inline;
}
.nav{
margin-top : 30px;
}
}
But is visible on every screen resolution. Seems like display: none; isn't working.
Since you're using bootstrap, you can use visible-xs class on them:
<li class="visible-xs">BUTTON 4</li>
Now, it will be visible in xs-devices and hidden in other devices.
BUTTON 4
is best approach however if you do not follow bootstrap then simply you can use display:inline !important;
As the css which is lower on page has more priority and in your case I think there is some hierarchy problem.
Try this deisplay:inline !important;
It is probably late but since I noticed you are using bootstrap you can use .d-block .d-sm-none as your class to make it only visible on xs- small devices.
Use this as a guide.