when i click on the navbar icon on my mobile/tablet the navabr opens but then it goes away, but the navbar still thinks that the navbar is open, when i reclick on the navbar icon it closes then (can't see it close), but when i click again to open it, it's still the same.
I added a gif(sorry for the low resolution) to show you what i get.GIF
The Navbar code:
<div class="navbar-fixed-top">
<div id="menu">
<div class="menu--topbar">
<div class="container">
<div class="menu-topbar--contact">
<ul class="nav navbar-nav">
<li><a style="color:#fff" href="MAILTO:XXXXXXXXXXXXXXXXXXXXX"><i class="fa fa-envelope"></i><span href="mailto:XXXXXXXXXXXXXXXXXXXXX"></span>EMAILXXXXX</a></li>
<li><a style="color:#fff" href="tel:XXXXXXXXXX"><i class="fa fa-phone"></i><span href="tel:XXXXXXXXX"></span> XXXXXXXXX</a></li>
</ul>
</div>
</div>
</div>
<nav id="secondaryMenu" class="navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#secondaryNavbar" aria-expanded="false" aria-controls="secondaryNavbar"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button>
<div class="login-btn hidden-lg hidden-md hidden-sm"> Nefsani </div>
</div>
<div id="secondaryNavbar" class="reset-padding navbar-collapse collapse ">
<ul class="secondary-menu-links nav navbar-nav">
<li>Home</li>
<li>Over mezelf</li>
<li class="dropdown"> Mijn aanbod<span class="caret"></span>
<ul class="dropdown-menu">
<li>relatietherapie</li>
<li>individuele therapie </li>
<li>persoonlijke consultgesprekken</li>
</ul>
</li>
<li>Tarieven en terugbetaling</li>
<li>Contacteer mij</li>
</ul>
<ul class="secondary-menu-links nav navbar-nav navbar-right hidden-xs">
<li>Nefsani</li>
</ul>
</div>
</div>
</nav>
The Navbar CSS:
#secondaryMenu {
position: relative;
margin-bottom: 0;
background-color: #54bceb;
border: none;
border-radius: 0;
box-shadow: none;
z-index: 1;
}
#secondaryMenu.sticky {
position: fixed;
box-shadow: 0 0 4px rgba(0,0,0,.14),0 4px 8px rgba(0,0,0,.28);
}
#secondaryMenu .navbar-toggle {
border: none;
}
#secondaryMenu .navbar-toggle .icon-bar {
background-color: #fff;
}
#secondaryMenu a.navbar-brand {
display: block;
padding: 10px 0;
margin-top: 18px;
margin-left: 0;
color: #303030;
font-size: 24px;
font-weight: 700;
}
#secondaryMenu a.navbar-brand span {
color: #4584b4;
}
#secondaryMenu .navbar-header .login-btn > .btn {
color: #fff;
background-color: #303030;
border: none;
border-radius: 0;
-webkit-transition: color .25s ease,background-color .25s ease-in-out;
transition: color .25s ease,background-color .25s ease-in-out;
}
#secondaryMenu .navbar-header .login-btn > .btn:focus, #secondaryMenu .navbar-header .login-btn > .btn:hover {
color: #303030;
background-color: #fff;
box-shadow: none;
outline: 0;
}
.secondary-menu-links li a {
margin-right: 3px;
padding: 24px 14px 21px;
border-bottom: 3px solid transparent;
color: #fff;
font-size: 18px;
line-height: 22px;
font-weight: 700;
-webkit-transition: color .25s ease,background-color .25s ease-in-out,border-color .25s ease;
transition: color .25s ease,background-color .25s ease-in-out,border-color .25s ease;
}
.secondary-menu-links li:last-child a {
margin-right: 0;
}
.secondary-menu-links > .dropdown > a > .caret {
margin-left: 8px;
}
.secondary-menu-links li a .fa {
display: block;
margin: 0 auto 3px;
font-size: 20px;
}
.secondary-menu-links .open > a, .secondary-menu-links .open > a:focus, .secondary-menu-links .open > a:hover, .secondary-menu-links li a:focus, .secondary-menu-links li a:hover, .secondary-menu-links li.active > a, .secondary-menu-links li.active > a:hover {
background-color: transparent;
border-color: #fff;
}
.secondary-menu-links > .dropdown:hover > .dropdown-menu {
display: block;
}
.secondary-menu-links li .dropdown-menu {
padding: 0;
background-color: #fff;
border-style: solid;
border-width: 3px 0;
border-color: #fff;
border-radius: 0;
}
.secondary-menu-links li .dropdown-menu li a {
margin-right: 0;
padding: 10px 15px;
color: #303030;
font-size: 16px;
line-height: 20px;
border: none;
}
.secondary-menu-links > .dropdown > .dropdown-menu > li.active > a, .secondary-menu-links > .dropdown > .dropdown-menu > li.active > a:focus, .secondary-menu-links > .dropdown > .dropdown-menu > li.active > a:hover, .secondary-menu-links > .dropdown > .dropdown-menu > li > a:focus, .secondary-menu-links > .dropdown > .dropdown-menu > li > a:hover {
color: #fff;
background-color: #00678d;
}
.secondary-menu-links.navbar-right {
padding-right: 15px;
}
.secondary-menu-links > li > a.btn {
padding: 24px 30px;
color: #fff;
background-color: #303030;
border: none;
border-radius: 0;
-webkit-transition: color .25s ease,background-color .25s ease-in-out;
transition: color .25s ease,background-color .25s ease-in-out;
}
.secondary-menu-links > li > a.btn:focus, .secondary-menu-links > li > a.btn:hover {
color: #303030;
background-color: #fff;
box-shadow: none;
}
If you need any more informaton let me know.
thanks in advance!
try with all these includes, working fine now.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
#secondaryMenu {
position: relative;
margin-bottom: 0;
background-color: #54bceb;
border: none;
border-radius: 0;
box-shadow: none;
z-index: 1;
}
#secondaryMenu.sticky {
position: fixed;
box-shadow: 0 0 4px rgba(0,0,0,.14),0 4px 8px rgba(0,0,0,.28);
}
#secondaryMenu .navbar-toggle {
border: none;
}
#secondaryMenu .navbar-toggle .icon-bar {
background-color: #fff;
}
#secondaryMenu a.navbar-brand {
display: block;
padding: 10px 0;
margin-top: 18px;
margin-left: 0;
color: #303030;
font-size: 24px;
font-weight: 700;
}
#secondaryMenu a.navbar-brand span {
color: #4584b4;
}
#secondaryMenu .navbar-header .login-btn > .btn {
color: #fff;
background-color: #303030;
border: none;
border-radius: 0;
-webkit-transition: color .25s ease,background-color .25s ease-in-out;
transition: color .25s ease,background-color .25s ease-in-out;
}
#secondaryMenu .navbar-header .login-btn > .btn:focus, #secondaryMenu .navbar-header .login-btn > .btn:hover {
color: #303030;
background-color: #fff;
box-shadow: none;
outline: 0;
}
.secondary-menu-links li a {
margin-right: 3px;
padding: 24px 14px 21px;
border-bottom: 3px solid transparent;
color: #fff;
font-size: 18px;
line-height: 22px;
font-weight: 700;
-webkit-transition: color .25s ease,background-color .25s ease-in-out,border-color .25s ease;
transition: color .25s ease,background-color .25s ease-in-out,border-color .25s ease;
}
.secondary-menu-links li:last-child a {
margin-right: 0;
}
.secondary-menu-links > .dropdown > a > .caret {
margin-left: 8px;
}
.secondary-menu-links li a .fa {
display: block;
margin: 0 auto 3px;
font-size: 20px;
}
.secondary-menu-links .open > a, .secondary-menu-links .open > a:focus, .secondary-menu-links .open > a:hover, .secondary-menu-links li a:focus, .secondary-menu-links li a:hover, .secondary-menu-links li.active > a, .secondary-menu-links li.active > a:hover {
background-color: transparent;
border-color: #fff;
}
.secondary-menu-links > .dropdown:hover > .dropdown-menu {
display: block;
}
.secondary-menu-links li .dropdown-menu {
padding: 0;
background-color: #fff;
border-style: solid;
border-width: 3px 0;
border-color: #fff;
border-radius: 0;
}
.secondary-menu-links li .dropdown-menu li a {
margin-right: 0;
padding: 10px 15px;
color: #303030;
font-size: 16px;
line-height: 20px;
border: none;
}
.secondary-menu-links > .dropdown > .dropdown-menu > li.active > a, .secondary-menu-links > .dropdown > .dropdown-menu > li.active > a:focus, .secondary-menu-links > .dropdown > .dropdown-menu > li.active > a:hover, .secondary-menu-links > .dropdown > .dropdown-menu > li > a:focus, .secondary-menu-links > .dropdown > .dropdown-menu > li > a:hover {
color: #fff;
background-color: #00678d;
}
.secondary-menu-links.navbar-right {
padding-right: 15px;
}
.secondary-menu-links > li > a.btn {
padding: 24px 30px;
color: #fff;
background-color: #303030;
border: none;
border-radius: 0;
-webkit-transition: color .25s ease,background-color .25s ease-in-out;
transition: color .25s ease,background-color .25s ease-in-out;
}
.secondary-menu-links > li > a.btn:focus, .secondary-menu-links > li > a.btn:hover {
color: #303030;
background-color: #fff;
box-shadow: none;
}
</style>
</head>
<body>
<div class="navbar-fixed-top">
<div id="menu">
<div class="menu--topbar">
<div class="container">
<div class="menu-topbar--contact">
<ul class="nav navbar-nav">
<li><a style="color:#fff" href="MAILTO:XXXXXXXXXXXXXXXXXXXXX"><i class="fa fa-envelope"></i><span href="mailto:XXXXXXXXXXXXXXXXXXXXX"></span>EMAILXXXXX</a></li>
<li><a style="color:#fff" href="tel:XXXXXXXXXX"><i class="fa fa-phone"></i><span href="tel:XXXXXXXXX"></span> XXXXXXXXX</a></li>
</ul>
</div>
</div>
</div>
<nav id="secondaryMenu" class="navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#secondaryNavbar" aria-expanded="false" aria-controls="secondaryNavbar"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button>
<div class="login-btn hidden-lg hidden-md hidden-sm"> Nefsani </div>
</div>
<div id="secondaryNavbar" class="reset-padding navbar-collapse collapse ">
<ul class="secondary-menu-links nav navbar-nav">
<li>Home</li>
<li>Over mezelf</li>
<li class="dropdown"> Mijn aanbod<span class="caret"></span>
<ul class="dropdown-menu">
<li>relatietherapie</li>
<li>individuele therapie </li>
<li>persoonlijke consultgesprekken</li>
</ul>
</li>
<li>Tarieven en terugbetaling</li>
<li>Contacteer mij</li>
</ul>
<ul class="secondary-menu-links nav navbar-nav navbar-right hidden-xs">
<li>Nefsani</li>
</ul>
</div>
</div>
</nav>
<div class="container">
<h3>Collapsible Navbar</h3>
<p>In this example, the navigation bar is hidden on small screens and replaced by a button in the top right corner (try to re-size this window).
<p>Only when the button is clicked, the navigation bar will be displayed.</p>
</div>
</body>
</html>
You may be using outdated version of bootstrap link to import its javascript file. After updating the link, the problem was solved for me.
Hope it helps someone!
Related
I've taken a bootstrap theme and the hamburger menu on mobile wasn't working. When the menu is toggled open on mobile, it will open and then quickly close but the menu links are still able to be pressed as if they were there, like they're invisible.
I've checked that the original files had a broken menu and it doesn't. I've tried googling to find out what the problem is but I'm struggling to find an answer.
The only thing I have is that when i use .menu {position: absolute;} then the menu on mobile opens and then quickly closes. When I changed it to .menu {position: relative;} then the menu stays open, but is all right aligned and doesn't look good.
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse.collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="navbar-brand">
<div id="logo" class="pull-left">
<img src="images\robark-Logo.png" alt="Robark Solutions Logo" title="Robark Solutions" width="260" height="90"/>
</div>
</div>
</div>
<div class="navbar-collapse collapse">
<div class="menu">
<ul class="nav nav-tabs" role="tablist">
<li role="presentation">Home</li>
<li role="presentation">About Us</li>
<li role="presentation">Services</li>
<li role="presentation">Portfolio</li>
<li role="presentation">Contact</li>
</ul>
</div>
</div>
</div>
</div>
</nav>
CSS:
.navigation {
background-color:#fff;
padding:0;
}
.navbar-brand {
min-height: 100px;
}
.navbar-brand h1 {
margin-top:9px;
padding-top:5px;
float: left;
font-size: 25px;
color:#333;
text-transform:uppercase;
font-weight:900;
}
.navbar-brand h1 span {
color: #F0A830;
}
.menu {
position: absolute;
overflow: hidden;
font-size:12px;
float:right;
text-transform:uppercase;
font-weight:700;
}
.menu:active ul {
display: block;
}
.menu ul.nav-tabs li {
color:#000;
}
.nav-tabs {
border-bottom: 0;
}
.nav-tabs > li {
float: left;
margin-bottom: 0;
}
.nav-tabs > li > a {
border-radius:0;
color:#333;
padding:30px;
}
.nav-tabs > li > a:hover {
color: #F0A830;
border-color: #fff #fff #fff;
border-radius:0;
background-color:#fff;
transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-webkit-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
}
.nav-tabs > li > a.active {
color: #F0A830;
border-radius:0;
transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-webkit-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
}
#media (max-width: 767px) {
.navbar-brand {
min-height: 85px;
padding-top: 6px;
}
.navbar-brand h1 {
margin-top: 0;
}
.nav-tabs > li {
float: none;
display: block;
}
.menu {
position: absolute;
left: 0;
right: 0;
background: #fff;
}
.menu .collapse {
display: none;
visibility: hidden;
}
.menu-default{
z-index: 1030;
}
.menu:active ul {
display: block;
}
.nav-tabs > li > a {
padding:15px 15px;
border-bottom: 1px solid #f3f3f3;
}
.nav-tabs > li > a:hover {
border-color: #f3f3f3;
}
}
Bootstrap CSS:
#media (min-width: 768px) {
.navbar-header {
float: left;
}
}
.navbar-collapse {
padding-right: 15px;
padding-left: 15px;
overflow-x: visible;
border-top: 1px solid transparent;
-webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
-webkit-overflow-scrolling: touch;
}
.navbar-collapse.in {
overflow-y: auto;
}
#media (min-width: 768px) {
.navbar-collapse {
width: auto;
border-top: 0;
-webkit-box-shadow: none;
box-shadow: none;
}
.navbar-collapse.collapse {
display: block!important;
height: auto!important;
padding-bottom: 0;
overflow: visible!important;
visibility: visible!important;
}
.navbar-fixed-top .navbar-collapse,
.navbar-static-top .navbar-collapse,
.navbar-fixed-bottom .navbar-collapse {
padding-right: 0;
padding-left: 0;
}
}
.navbar-fixed-top,
.navbar-fixed-bottom {
position: fixed;
right: 0;
left: 0;
z-index: 1030;
}
.navbar-fixed-top .navbar-collapse,
.navbar-fixed-bottom .navbar-collapse {
max-height: 340px;
}
<div class="navbar-header"></div>
<div class="navbar-header"></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><a class="smoth-scroll" href="#home">Home</a></li>
<li><a class="smoth-scroll" href="#aboutus">About Us</a></li>
<li><a class="smoth-scroll" href="#services">Services</a></li>
<li><a class="smoth-scroll" href="#ourteam">Our Team</a></li>
<li><a class="smoth-scroll" href="#testimonial">Testimonials</a></li>
<li><a class="smoth-scroll" href="#portfolio">Portfolio</a></li>
<li><a class="smoth-scroll" href="#contactus">Contact Us</a></li>
</ul>
</div>
<!-- /.navbar-collapse --></nav>
================================================
7. Navigation
================================================
*/
.menu-bg {
z-index: 999;
}
.menu-bg .basement-logo {
padding-top: 5px;
transition: all 0.3s ease 0s;
}
.navbar-default {
background-color: inherit;
border-color: inherit;
}
.navbar {
border-radius: 0;
min-height: auto;
margin: 0;
border: none;
z-index: 9;
}
.navbar-collapse {
float: right;
margin: 0;
padding: 0;
}
.navbar-brand {
padding: 0;
height: auto;
}
.navbar-nav > li {
padding: 0;
margin: 0 0 0 1px;
}
.navbar-default .navbar-nav li a {
color: #000;
font-size: 13px;
font-weight: 600;
padding: 30px 13px;
transition: all 0.3s ease 0s;
text-transform: uppercase;
background-color: inherit;
font-family: "Roboto",sans-serif;
letter-spacing: 1px;
}
.navbar-default .navbar-nav > li > a:focus, .navbar-default .navbar-nav > li > a:hover {
background-color: #DC143C !important;
color: #000;
}
.menu-bg .navbar-default .navbar-nav li a {
padding: 20px 10px;
transition: all 0.3s ease 0s;
}
.navbar-default .navbar-nav > .active > a, .navbar-default .navbar-nav > .active > a:focus, .navbar-default .navbar-nav > .active > a:hover {
background-color: #DC143C !important;
color: #000;
}
/*
I copy and pasted this from CSS code editor in file manager through my Cpanel account. I am trying to change the hover color to a red (#DC143C), but am failing miserably. I really appreciate your help so thanks in advance! I think it's obvious I am a novice and I am still trying to figure out the relationship between CSS, JavaScript, and HTML, so please have some patience. I've finally figured out basic networking, but this is a whole new ball game. Again, thanks so much for your help.
You had forgot to add ul before li in css. use below code it works.
<html>
<head>
<style>
.menu-bg {
z-index: 999;
}
.menu-bg .basement-logo {
padding-top: 5px;
transition: all 0.3s ease 0s;
}
.navbar-default {
background-color: inherit;
border-color: inherit;
}
.navbar {
border-radius: 0;
min-height: auto;
margin: 0;
border: none;
z-index: 9;
}
.navbar-collapse {
float: right;
margin: 0;
padding: 0;
}
.navbar-brand {
padding: 0;
height: auto;
}
.navbar-nav > li {
padding: 0;
margin: 0 0 0 1px;
}
.navbar-default .navbar-nav li a {
color: #000;
font-size: 13px;
font-weight: 600;
padding: 30px 13px;
transition: all 0.3s ease 0s;
text-transform: uppercase;
background-color: inherit;
font-family: "Roboto",sans-serif;
letter-spacing: 1px;
}
.navbar-default .navbar-nav > ul > li > a:focus, .navbar-default .navbar-nav > ul > li > a:hover {
background-color: #DC143C !important;
color: #000;
}
.menu-bg .navbar-default .navbar-nav ul li a {
padding: 20px 10px;
transition: all 0.3s ease 0s;
}
.navbar-default .navbar-nav > .active > a, .navbar-default .navbar-nav > .active > a:focus, .navbar-default .navbar-nav > .active > a:hover {
background-color: #DC143C !important;
color: #000;
}
</style>
</head>
<body>
<div class="navbar-default">
<div class="navbar-nav" >
<ul>
<li style="height:50px;">
dfsdgdsgs </li>
</div>
</div>
</body>
</html>
Just simply insert the below css code to your CSS file. And I've provided the Codepen Link For you Check that
https://codepen.io/anon/pen/dePmEY
.navbar-collapse ul li a:hover{
color:black;
background-color:#DC143C;
}
For further queries please provide your HTML code.
.menu-bg {
z-index: 999;
}
.menu-bg .basement-logo {
padding-top: 5px;
transition: all 0.3s ease 0s;
}
.navbar-default {
background-color: inherit;
border-color: inherit;
}
.navbar {
border-radius: 0;
min-height: auto;
margin: 0;
border: none;
z-index: 9;
}
.navbar-collapse {
float: right;
margin: 0;
padding: 0;
}
.navbar-brand {
padding: 0;
height: auto;
}
.navbar-nav > li {
padding: 0;
margin: 0 0 0 1px;
}
.navbar-default .navbar-nav li a {
color: #000;
font-size: 13px;
font-weight: 600;
padding: 30px 13px;
transition: all 0.3s ease 0s;
text-transform: uppercase;
background-color: inherit;
font-family: "Roboto",sans-serif;
letter-spacing: 1px;
}
.navbar-default .navbar-nav > li > a:focus, .navbar-default .navbar-nav > li > a:hover {
background-color: #DC143C !important;
color: #000;
}
.menu-bg .navbar-default .navbar-nav li a {
padding: 20px 10px;
transition: all 0.3s ease 0s;
}
.navbar-default .navbar-nav > .active > a, .navbar-default .navbar-nav > .active > a:focus, .navbar-default .navbar-nav > .active > a:hover {
background-color: #DC143C !important;
color: #000;
}
.navbar-collapse ul li a:hover{
color:black;
background-color:#DC143C;
}
<div class="navbar-header"></div>
<div class="navbar-header"></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><a class="smoth-scroll" href="#home">Home</a></li>
<li><a class="smoth-scroll" href="#aboutus">About Us</a></li>
<li><a class="smoth-scroll" href="#services">Services</a></li>
<li><a class="smoth-scroll" href="#ourteam">Our Team</a></li>
<li><a class="smoth-scroll" href="#testimonial">Testimonials</a></li>
<li><a class="smoth-scroll" href="#portfolio">Portfolio</a></li>
<li><a class="smoth-scroll" href="#contactus">Contact Us</a></li>
</ul>
</div>
I want to center the logo. I was able to center it by defining the padding and stuff but the problem is that the logo moves when I try to view it on a different monitor/resolution.
Here's the Code:
/* Navigation */
.navbar {-moz-border-radius: 0;-webkit-border-radius: 0;border-radius: 0;margin-bottom: 0;}
.navbar .container {text-align: center; position: center; background-color: #fff; right:55px;}
.navbar-default {-moz-transition: all 0.3s ease-out;-o-transition: all 0.3s ease-out;-webkit-transition: all 0.3s ease-out;transition: all 0.3s ease-out;width: 100%;border: none;border-bottom: 0px solid #e7e7e7;background-color: #fff; }
.navbar-default .navbar-nav > li > a {color: #000;font-weight: normal;font-size: 15px; display: inline-block; padding-right: 23px; padding-left: 23px}
.navbar-default .navbar-nav > li > a:hover {background-color: transparent;color: #005FA6;}
.navbar-default .navbar-nav > .open > a,.navbar-default .navbar-nav > .open > a:hover,.navbar-default .navbar-nav > .open > a:focus {background-color: transparent;color: #005FA6;}
.navbar-default .navbar-nav .active > a,.navbar-default .navbar-nav .active > a:hover,.navbar-default .navbar-nav .active > a:focus {color: #005FA6;background-color: transparent;}
.navbar-default .navbar-toggle {margin: 10px 0 0 15px;}
.navbar-default .navbar-toggle,.navbar-default .navbar-toggle:hover,.navbar-default .navbar-toggle:focus {border: none;background: #f3f3f3;}
.navbar-default .navbar-toggle i {font-size: 31px;}
.navbar-default .navbar-collapse {float: right; border-top: none;padding-left: 0;padding-right: 0;}
.navbar-brand>img {padding: 5px; align: center;}
<nav class="navbar navbar-default">
<div class="container">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-navbar-collapse">
<span class="sr-only">Toggle Navigation</span>
<i class="fa fa-bars"></i>
</button>
<a href="index.php" class="navbar-brand">
<img src="img/corelogo.png" alt="" height="150" width="150">
</a>
</div>
</nav>
Set your logo <img> tag as display:block. Then give it a left and right margin of auto.
Example below:
/* Navigation */
.navbar {
-moz-border-radius: 0;
-webkit-border-radius: 0;
border-radius: 0;
margin-bottom: 0;
}
.navbar .container {
text-align: center;
position: center;
background-color: #fff;
right: 55px;
}
.navbar-default {
-moz-transition: all 0.3s ease-out;
-o-transition: all 0.3s ease-out;
-webkit-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
width: 100%;
border: none;
border-bottom: 0px solid #e7e7e7;
background-color: #fff;
}
.navbar-default .navbar-nav>li>a {
color: #000;
font-weight: normal;
font-size: 15px;
display: inline-block;
padding-right: 23px;
padding-left: 23px
}
.navbar-default .navbar-nav>li>a:hover {
background-color: transparent;
color: #005FA6;
}
.navbar-default .navbar-nav>.open>a,
.navbar-default .navbar-nav>.open>a:hover,
.navbar-default .navbar-nav>.open>a:focus {
background-color: transparent;
color: #005FA6;
}
.navbar-default .navbar-nav .active>a,
.navbar-default .navbar-nav .active>a:hover,
.navbar-default .navbar-nav .active>a:focus {
color: #005FA6;
background-color: transparent;
}
.navbar-default .navbar-toggle {
margin: 10px 0 0 0;
}
.navbar-default .navbar-toggle,
.navbar-default .navbar-toggle:hover,
.navbar-default .navbar-toggle:focus {
border: none;
background: #f3f3f3;
}
.navbar-default .navbar-toggle i {
font-size: 31px;
}
.navbar-default .navbar-collapse {
float: right;
border-top: none;
padding-left: 0;
padding-right: 0;
}
.navbar-brand img {
border:1px solid black;
width:150px;
height:150px;
display:block;
margin: 15px auto 0px auto;
}
<nav class="navbar navbar-default">
<div class="container">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-navbar-collapse">
<span class="sr-only">Toggle Navigation</span>
<i class="fa fa-bars"></i>
</button>
<a href="index.php" class="navbar-brand">
<img src="img/corelogo.png" alt="" height="150" width="150">
</a>
</div>
</nav>
You just need make your image a block element by adding display: block; and then adding an auto margin with margin: 0 auto;
Here is your code: .navbar-brand > img { display: block; margin: 0 auto;}
<style>
.navbar {-moz-border-radius: 0;-webkit-border-radius: 0;border-radius: 0;margin-bottom: 0;}
.navbar .container {text-align: center; position: center; background-color: #fff; right:55px;}
.navbar-default {-moz-transition: all 0.3s ease-out;-o-transition: all 0.3s ease-out;-webkit-transition: all 0.3s ease-out;transition: all 0.3s ease-out;width: 100%;border: none;border-bottom: 0px solid #e7e7e7;background-color: #fff; }
.navbar-default .navbar-nav > li > a {color: #000;font-weight: normal;font-size: 15px; display: inline-block; padding-right: 23px; padding-left: 23px}
.navbar-default .navbar-nav > li > a:hover {background-color: transparent;color: #005FA6;}
.navbar-default .navbar-nav > .open > a,.navbar-default .navbar-nav > .open > a:hover,.navbar-default .navbar-nav > .open > a:focus {background-color: transparent;color: #005FA6;}
.navbar-default .navbar-nav .active > a,.navbar-default .navbar-nav .active > a:hover,.navbar-default .navbar-nav .active > a:focus {color: #005FA6;background-color: transparent;}
.navbar-default .navbar-toggle {margin: 10px 0 0;}
.navbar-default .navbar-toggle,.navbar-default .navbar-toggle:hover,.navbar-default .navbar-toggle:focus {border: none;background: #f3f3f3;}
.navbar-default .navbar-toggle i {font-size: 31px;}
.navbar-default .navbar-collapse {float: right; border-top: none;padding-left: 0;padding-right: 0;}
.navbar-brand > img { display: block; margin: 0 auto;}
</style>
<nav class="navbar navbar-default">
<div class="container">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-navbar-collapse">
<span class="sr-only">Toggle Navigation</span>
<i class="fa fa-bars"></i>
</button>
<a href="index.php" class="navbar-brand">
<img class="my-image" src="img/corelogo.png" alt="" height="150" width="150">
</a>
</div>
</nav>
How can I make other slide-down menus close when clicking on another menu item? Right now all menu items are opening one by one and they can only be closed by clicking on the item again.
Here's a demo: http://bootsnipp.com/snippets/33qKz
And here's the code
function htmlbodyHeightUpdate(){
var height3 = $( window ).height()
var height1 = $('.nav').height()+50
height2 = $('.main').height()
if(height2 > height3){
$('html').height(Math.max(height1,height3,height2)+10);
$('body').height(Math.max(height1,height3,height2)+10);
}
else
{
$('html').height(Math.max(height1,height3,height2));
$('body').height(Math.max(height1,height3,height2));
}
}
$(document).ready(function () {
htmlbodyHeightUpdate()
$( window ).resize(function() {
htmlbodyHeightUpdate()
});
$( window ).scroll(function() {
height2 = $('.main').height()
htmlbodyHeightUpdate()
});
});
/* Adding gvnix styles css - NO COPIAR */
#import 'http://geo-gvnix.rhcloud.com/resources/styles/standard.css';
/* Custom fixed navs */
header.navbar+nav.navbar {
/* margin-top: 20px;same margin-bottom .navbar */
}
.navbar.navbar-default.navbar-fixed-top {
margin-top: 50px;
}
.sidebar.navbar-fixed-top {
margin-top: 100px;
}
#media (min-width: 768px) and (max-width: 998px) {
.navbar.navbar-default.navbar-fixed-top {
margin-top: 100px;
}
.sidebar.navbar-fixed-top {
margin-top: 150px;
}
}
/* Custom navbar default: global*/
.navbar.navbar-default {
background-color: #f8f8f8;
border-color: #e7e7e7;
margin: 0;
border-radius: 0;
}
.navbar.navbar-default .navbar-brand {
color: #666;
text-shadow: none;
min-width: 150px;
}
.navbar.navbar-default .navbar-nav > li > a {
color: #666;
text-shadow: none;
}
.navbar.navbar-default .navbar-nav > li > a {
color: #666;
text-shadow: none;
}
.navbar.navbar-default .navbar-nav > li > a:hover {
color: #acc47f;
}
.navbar.navbar-default .navbar-nav > .active > a {
color: #fff;
background-color: #acc47f;
}
.navbar.navbar-default .navbar-nav > .active > a:hover {
color: #608224;
background-color: #acc47f;
}
.navbar.navbar-default .caret {
border-top-color: #ccc;
border-bottom-color: #ccc;
}
.navbar.navbar-default .caret:hover {
border-top-color: #333;
border-bottom-color: #333;
}
/* Custom sidebar menu */
/*Remove rounded coners*/
nav.sidebar.navbar {
border-radius: 0px;
}
nav.sidebar,
.main {
-webkit-transition: margin 200ms ease-out;
-moz-transition: margin 200ms ease-out;
-o-transition: margin 200ms ease-out;
transition: margin 200ms ease-out;
}
/* Add gap to nav and right windows.*/
.main {
padding: 10px 10px 0 10px;
}
/* .....NavBar: Icon only with coloring/layout.....*/
/*small/medium side display*/
#media (min-width: 768px) {
/*Allow main to be next to Nav*/
.main {
position: absolute;
width: calc(100% - 40px);
/*keeps 100% minus nav size*/
margin-left: 40px;
float: right;
}
/*lets nav bar to be showed on mouseover*/
nav.sidebar:hover + .main {
margin-left: 200px;
}
/*Center Brand*/
nav.sidebar.navbar.sidebar>.container .navbar-brand,
.navbar>.container-fluid .navbar-brand {
margin-left: 0px;
}
/*Center Brand*/
nav.sidebar .navbar-brand,
nav.sidebar .navbar-header {
text-align: center;
width: 100%;
margin-left: 0px;
}
/*Center Icons*/
nav.sidebar a {
padding-right: 13px;
min-width: 100px;
}
/*custom sidebar nav*/
nav.sidebar ul.nav.navbar-nav {
margin: 0;
}
nav.sidebar.navbar-inverse .navbar-nav .open .dropdown-menu>li>a {
color: white;
}
/*adds border top to first nav box */
nav.sidebar .navbar-nav > li:first-child {
border-top: 1px #e5e5e5 solid;
}
/*adds border to bottom nav boxes*/
nav.sidebar .navbar-nav > li {
border-bottom: 1px #e5e5e5 solid;
}
/*adds background on hover*/
nav.sidebar .navbar-nav > li:hover {
color: #fff;
background-color: #43600E;
}
/*removes border last element*/
nav.sidebar .navbar-nav > li.last {
border-bottom: none;
}
/* Colors/style dropdown box*/
nav.sidebar .navbar-nav .open .dropdown-menu {
position: static;
float: none;
width: auto;
margin-top: 0;
background-color: transparent;
border: 0;
-webkit-box-shadow: none;
box-shadow: none;
}
/*allows nav box to use 100% width*/
nav.sidebar .navbar-collapse,
nav.sidebar .container-fluid {
padding: 0 0px 0 0px;
}
/*colors dropdown box text */
.navbar-inverse .navbar-nav .open .dropdown-menu>li>a {
color: #777;
}
/*O quanto o menu irá esconder á esquerda*/
/*gives sidebar width/height*/
nav.sidebar {
width: 200px;
height: 100%;
margin-left: -270px;
float: left;
z-index: 8000;
margin-bottom: 0px;
}
/*give sidebar 100% width;*/
nav.sidebar li {
width: 100%;
}
/* Move nav to full on mouse over*/
nav.sidebar:hover {
margin-left: 0px;
}
/*for hiden things when navbar hidden*/
.forAnimate {
opacity: 0;
}
}
/* .....NavBar: Fully showing nav bar..... */
#media (min-width: 1330px) {
/* Allow main to be next to Nav
.main{
width: calc(100% - 200px); keeps 100% minus nav size
margin-left: 200px;
}
Show all nav
nav.sidebar{
margin-left: 0px;
float: left;
}
Show hidden items on nav
nav.sidebar .forAnimate{
opacity: 1;
} */
}
nav.sidebar .navbar-nav .open .dropdown-menu>li>a:hover,
nav.sidebar .navbar-nav .open .dropdown-menu>li>a:focus {
color: #CCC;
background-color: transparent;
}
nav:hover .forAnimate {
opacity: 1;
}
/*---- FIM SLIDE MENU*/
.nav-side-menu {
overflow: auto;
font-family: verdana;
font-size: 12px;
font-weight: 200;
background-color: #2e353d;
position: fixed;
top: 0px;
width: 300px;
height: 100%;
color: #e1ffff;
}
.nav-side-menu .brand {
background-color: #23282e;
line-height: 50px;
display: block;
text-align: center;
font-size: 14px;
}
.nav-side-menu .toggle-btn {
display: none;
}
.nav-side-menu ul,
.nav-side-menu li {
list-style: none;
padding: 0px;
margin: 0px;
line-height: 35px;
cursor: pointer;
/*
.collapsed{
.arrow:before{
font-family: FontAwesome;
content: "\f053";
display: inline-block;
padding-left:10px;
padding-right: 10px;
vertical-align: middle;
float:right;
}
}
*/
}
.nav-side-menu ul :not(collapsed) .arrow:before,
.nav-side-menu li :not(collapsed) .arrow:before {
font-family: FontAwesome;
content: "\f078";
display: inline-block;
padding-left: 10px;
padding-right: 10px;
vertical-align: middle;
float: right;
}
.nav-side-menu ul .active,
.nav-side-menu li .active {
border-left: 3px solid #d19b3d;
background-color: #4f5b69;
}
.nav-side-menu ul .sub-menu li.active,
.nav-side-menu li .sub-menu li.active {
color: #d19b3d;
}
.nav-side-menu ul .sub-menu li.active a,
.nav-side-menu li .sub-menu li.active a {
color: #d19b3d;
}
.nav-side-menu ul .sub-menu li,
.nav-side-menu li .sub-menu li {
background-color: #181c20;
border: none;
line-height: 28px;
border-bottom: 1px solid #23282e;
margin-left: 0px;
}
.nav-side-menu ul .sub-menu li:hover,
.nav-side-menu li .sub-menu li:hover {
background-color: #020203;
}
.nav-side-menu ul .sub-menu li:before,
.nav-side-menu li .sub-menu li:before {
font-family: FontAwesome;
content: "\f105";
display: inline-block;
padding-left: 10px;
padding-right: 10px;
vertical-align: middle;
}
.nav-side-menu li {
padding-left: 0px;
border-left: 3px solid #2e353d;
border-bottom: 1px solid #23282e;
}
.nav-side-menu li a {
text-decoration: none;
color: #e1ffff;
}
.nav-side-menu li a i {
padding-left: 10px;
width: 20px;
padding-right: 20px;
}
.nav-side-menu li:hover {
border-left: 3px solid #d19b3d;
background-color: #4f5b69;
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-o-transition: all 1s ease;
-ms-transition: all 1s ease;
transition: all 1s ease;
}
#media (max-width: 767px) {
.nav-side-menu {
position: relative;
width: 100%;
margin-bottom: 10px;
}
.nav-side-menu .toggle-btn {
display: block;
cursor: pointer;
position: absolute;
right: 10px;
top: 10px;
z-index: 10 !important;
padding: 3px;
background-color: #ffffff;
color: #000;
width: 40px;
text-align: center;
}
.brand {
text-align: left !important;
font-size: 22px;
padding-left: 20px;
line-height: 50px !important;
}
}
#media (min-width: 767px) {
.nav-side-menu .menu-list .menu-content {
display: block;
}
}
body {
margin: 0px;
padding: 0px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!--nav sidebar -->
<aside>
<nav class="navbar navbar-inverse sidebar navbar-fixed-top" role="navigation">
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<div class="nav-side-menu">
<div class="brand">Brand Logo</div>
<i class="fa fa-bars fa-2x toggle-btn" data-toggle="collapse" data-target="#menu-content"></i>
<div class="menu-list">
<ul id="menu-content" class="menu-content collapse out">
<li>
<a href="#">
<i class="fa fa-dashboard fa-lg"></i> Dashboard
</a>
</li>
<li data-toggle="collapse" data-target="#products" class="collapsed active">
<i class="fa fa-gift fa-lg"></i> UI Elements <i class="fa fa-gift fa-lg btn pull-right" style="margin-top:5px"></i>
</li>
<ul class="sub-menu collapse" id="products">
<li class="active">CSS3 Animation
</li>
<li>General
</li>
<li>Buttons
</li>
<li>Tabs & Accordions
</li>
<li>Typography
</li>
<li>FontAwesome
</li>
<li>Slider
</li>
<li>Panels
</li>
<li>Widgets
</li>
<li>Bootstrap Model
</li>
</ul>
<li data-toggle="collapse" data-target="#service" class="collapsed">
<i class="fa fa-globe fa-lg"></i> Services <span class="arrow"></span>
</li>
<ul class="sub-menu collapse" id="service">
<li>New Service 1</li>
<li>New Service 2</li>
<li>New Service 3</li>
</ul>
<li data-toggle="collapse" data-target="#new" class="collapsed">
<i class="fa fa-car fa-lg"></i> New <span class="arrow"></span>
</li>
<ul class="sub-menu collapse" id="new">
<li>New New 1</li>
<li>New New 2</li>
<li>New New 3</li>
</ul>
<li>
<a href="#">
<i class="fa fa-user fa-lg"></i> Profile
</a>
</li>
<li>
<a href="#">
<i class="fa fa-users fa-lg"></i> Users
</a>
</li>
</ul>
</div>
</div>
</nav>
</aside>
<div class="main">
</div>
Your HTML structure is not quite what Bootstrap expects and you won't be able to use the easy way of data-parent attribute on this structure (the items should be divs and have the class panel anyway). Please see documentation for more info if interested. But for your problem and something you can make work directly into your HTML. I added toggle-this class to all the parent menu items which are toggled and added the attribute data-parent="menu-content" to them also. Then I just use this jQuery function to see if there are any menus expanded on click and collapse all the other than the one just clicked like this:
$(document).on('click', '.toggle-this', function(event) {
event.stopPropagation();
var $this = $(this);
var parent = $this.data('parent');
var actives = $('#' + parent).find('[aria-expanded="true"]');
if (actives && actives.length) {
hasData = actives.data('collapse');
actives.collapse('hide');
}
var target = $this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, ''); //strip for ie7
$(target).collapse('toggle');
});
Here's a working JSFiddle: https://jsfiddle.net/thepio/x5j6v5fq/
Your html does not follow the documentation from bootstrap.
The right structure should be something like this:
<ul class="nav navbar-nav">
<li class="active">Dashboard</li>
<li class="dropdown">
UI Elements <span class="caret"></span>
<ul class="dropdown-menu">
<li>CSS3 Animation</li>
<li>General</li>
<li>Buttons</li>
...
</ul>
</li>
...
</ul>
I relize that this would mean you have to re-style some parts of your navigation, but it gives you the functionality that you want.
For more information check bootstraps documentation about navbars
Alternative you can make a little script to change/remove classes on the opened menu items when you click a new one.
I have a dropdown menu that is generated from WordPress so I do not want to change the HTML of it. i can change the CSS as needed though and I pretty much have ot working as I need it with the exception of an alignment issue with my dropdown menu.
Google Chrome
FireFox
Internet Explorer
From the images above you can see that IE and FIreFox display it the same but Chrome is always different from the 2. My Goal is to get this box to align perfectly with the right of the menu button and then get it to look that way in all 3 of these browsers.
I have extracted the HTML and CSS into a JSFiddle page for testing and playing around with here...
Code View: http://jsfiddle.net/jasondavis/hAb4k/
Full View for viewing the menu: http://jsfiddle.net/jasondavis/hAb4k/embedded/result/
My HTML
<nav id="head-nav-menu" class="nav-main" role="navigation" itemscope="itemscope" itemtype="http://schema.org/SiteNavigationElement">
<ul id="nav" class="nav nav-pills">
<li class="active menu-home">
Home
</li>
<li class="menu-about">
About
</li>
<li class="menu-projects">
Projects
</li>
<li class="menu-blog">
Blog
</li>
<li class="dropdown menu-services">
<a class="dropdown-toggle" data-toggle="dropdown" data-target="#" href="/services/">Services <b class="caret"></b></a>
<ul class="dropdown-menu">
<li class="menu-consulting">Consulting</li>
<li class="menu-magento-development">
Magento Development
</li>
<li class="menu-wordpress-development">
WordPress Development
</li>
<li class="menu-sugarcrm-development">
SugarCRM Development
</li>
<li class="menu-web-development">
Web Development
</li>
<li class="menu-seo">
SEO
</li>
</ul>
</li>
<li class="menu-contact">
Contact
</li>
</ul>
</nav>
CSS
body{
background: #40C8F4 !important;
}
nav ul, nav ol {
list-style: none;
list-style-image: none;
}
#head-nav-menu{
float: right;
margin-top: 29px;
}
#head-nav-menu li {
float: left;
position: relative;
padding: 0 2px 0 2px;
}
.nav a {
font-family: 'arial';
font-size: 18px;
padding: 8px 18px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
white-space: nowrap;
color: #fff;
opacity: 0.9;
letter-spacing: 1px;
text-decoration: none;
}
.menu-contact a {
border: 2px solid #FFF;
padding: 8px 18px;
transition: 0.05s linear;
-moz-transition: 0.05s linear;
-webkit-transition: 0.05s linear;
}
.nav .menu-contact a:hover {
background-color: #FFF;
color: #797979;
}
#nav ul a {
font-weight: 100;
}
.nav a:hover,
.nav > .active a {
opacity: 1;
background-color: #3DBCE6;
}
.nav > .active li a {
background-color: inherit;
}
.tinynav {
display: none;
width: 100%;
margin-top: .5em;
margin-bottom: .6em;
}
.nav li.button a {
background-color: rgba(255, 255, 255, 0.1);
border: 2px solid #FFF;
border-radius: 4px;
margin-top: 5px;
padding: 8px 18px;
font-family: 'ProximaNova-bold', Helvetica, Arial, sans-serif;
font-weight: normal;
margin-left: 16px;
color: #FFF !important;
}
.nav li.button a:hover {
background-color: #FFF;
opacity: 1;
color: #444 !important;
}
/* ==========================================================================
Main Container General Layout Styles
========================================================================== */
.header-container header {
padding-top: 13px;
padding-bottom: 18px;
}
/* Navigation > Dropdown Menus */
#nav .dropdown-menu,
#nav .children {
display: none;
padding: 0;
position: absolute;
z-index: 99999;
border: 1px solid #86DEFC;
width: 333%;
/*right: 8px;*/
left: -239%;
top: 23px;
background-color: #F2F9FC;
}
#nav .dropdown-menu li {
width: 195px;
float: left;
display: inline-block;
/*width: 50%;*/
}
.nav .dropdown-menu a {
color: #030303;
}
#nav li:hover > ul,
#nav ul li:hover > ul,
.dropdown:hover > ul {
display: inline-block;
-webkit-animation: fadeDown 250ms ease;
-moz-animation: fadeDown 250ms ease;
-ms-animation: fadeDown 250ms ease;
-o-animation: fadeDown 250ms ease;
animation: fadeDown 250ms ease;
background-color: #fff;
color: #000;
border: 1px solid #E9E9E9;
border-top: none;
}
#nav .dropdown-menu ul,
#nav .children ul {
left: 99.75%;
top: -1px;
}
#nav ul li,
#nav ul ul li {
margin-left: 0;
}
#nav ul li:first-child,
#nav ul ul li:first-child {
border-top: none;
}
#nav ul a,
#nav ul ul a {
font-size: 14px;
line-height: 21px;
text-align: left;
padding: 10px;
display: inline-block;
min-width: 125px;
border-bottom: none;
margin-bottom: 0 !important;
width: 100%;
letter-spacing: 1px;
font-family: arial;
}
#nav ul a:hover,
#nav ul ul a:hover {
color: #098EB9 !important;
background: none;
}
#nav ul ul.dropdown-menu a:hover {
width: 100%;
color: #63E924 !important;
border-bottom: none;
}
#nav li.current_page_item ul a,
#nav li.current-menu-parent ul a,
#nav li.current_page_parent ul a {
color: #000;
font-weight: 700;
}
#nav ul li.current-menu-item a {
color: #e9242e !important;
}
#head-nav-menu .nav li:hover a.dropdown-toggle {
background: #fff;
color: #000;
opacity: 1;
border-right: 1px solid #E7E7E7;
}
.nav .dropdown a:hover {
opacity: 1;
background-color: #fff;
}
#nav .dropdown-menu li:hover {
background: #F8F8F8;
}
Give display: block to .nav a
then remove left: 239% of #nav .dropdown-menu and give right: 2px and top: 38px to it.
Here is the edited demo for it.
http://jsfiddle.net/hAb4k/3/