I created a 'mega menu' with Bootstrap 3.
I'm having trouble getting the row that creates the mega-menu horizontally centered and retaining functionality. Element in question has class .mega-dropdown-menu.
<ul class="dropdown-menu mega-dropdown-menu row">
Here's the code snippet pertaining to my issue :
body {
background: #f0f0f0;
}
.dropdown-menu {
background-color: #f5f5f5;
}
.navbar-header {
background-color: #3a7dbb;
}
.collapse.navbar-collapse.js-navbar-collapse {
background-color: #3a7dbb;
/* ?=border-bottom: 5px solid #214f82 */
}
.navbar-default .navbar-nav > li > a.dropdown-toggle {
font-size: 16px;
color: white;
}
.dropdown > .dropdown-menu > li > a {
font-size: 16px;
}
.glyphicon-shopping-cart:before {
color: white;
}
.navbar .navbar-brand {
padding-top: 0px;
}
.dropdown > .dropdown-menu > li > a:hover {
background-color: white;
}
.navbar-nav > li > .dropdown-menu {
background-color: #f5f5f5;
margin-top: 20px;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
}
.navbar-default .navbar-nav > li > a {
/* width: 8em; */
font-weight: bold;
}
.mega-dropdown {
position: static !important;
width: 100%;
}
.mega-dropdown-menu {
padding: 20px 0px;
width: 100%;
box-shadow: none;
-webkit-box-shadow: none;
}
.center {
margin: auto;
}
.mega-dropdown-menu > li > ul {
padding: 0;
margin: 0;
}
.mega-dropdown-menu > li > ul > li {
list-style: none;
}
.mega-dropdown-menu > li > ul > li > a {
display: block;
padding: 3px 20px;
clear: both;
font-weight: normal;
line-height: 1.428571429;
color: #262626;
white-space: normal;
}
.i-am-centered {
margin: auto;
max-width: 300px;
}
.mega-dropdown-menu > li ul > li > a {
font-size: 16px;
}
.mega-dropdown-menu > li ul > li > a:hover,
.mega-dropdown-menu > li ul > li > a:focus {
text-decoration: none;
color: #444;
background-color: white;
}
li.dropdown:hover {
background-color: #c3c1c1;
}
ul.dropdown-menu.mega-dropdown-menu.row {
width: 80%;
}
.mega-dropdown-menu .dropdown-header {
color: #428bca;
font-size: 18px;
font-weight: bold;
}
.mega-dropdown-menu .dropdown-header > a {
color: #428bca;
font-size: 18px;
font-weight: bold;
padding-left: 0;
}
.mega-dropdown-menu form {
margin: 3px 20px;
}
.mega-dropdown-menu .form-group {
margin-bottom: 3px;
}
.navbar-default .navbar-nav .open .dropdown-menu > li > a {
color: black !important;
}
#media only screen and (min-width: 768px) {
.dropdown:hover > .dropdown-menu {
display: block;
}
.dropdown > .dropdown-toggle:active {
pointer-events: none;
}
}
/* .mega-dropdown-menu:before {
content: "";
border-bottom: 15px solid #fff;
border-right: 17px solid transparent;
border-left: 17px solid transparent;
position: absolute;
top: -15px;
left: 285px;
z-index: 10;
}
.mega-dropdown-menu:after {
content: "";
border-bottom: 17px solid #ccc;
border-right: 19px solid transparent;
border-left: 19px solid transparent;
position: absolute;
top: -17px;
left: 283px;
z-index: 8;
} */
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<div class="">
<nav class="navbar navbar-default">
<div class="navbar-header">
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".js-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="#"><img src="https://brm.institute/wp-content/themes/brmi/images/brm-institute-logo.png"></a>
</div>
<div class="collapse navbar-collapse js-navbar-collapse">
<ul class="nav navbar-nav">
<li class="dropdown mega-dropdown">
Dummy MegaMenu<span class="caret"></span>
<ul class="dropdown-menu mega-dropdown-menu row">
<li class="col-sm-4">
<ul>
<li class="dropdown-header">Dresses</li>
<li>Unique Features</li>
<li>Image Responsive</li>
<li>Auto Carousel</li>
<li>Newsletter Form</li>
<li>Four columns</li>
<li class="divider"></li>
<li class="dropdown-header">Tops</li>
<li>Good Typography</li>
</ul>
</li>
<li class="col-sm-4">
<ul>
<li class="dropdown-header">Jackets</li>
<li>Easy to customize</li>
<li>Glyphicons</li>
<li>Pull Right Elements</li>
<li class="divider"></li>
<li class="dropdown-header">Pants</li>
<li>Coloured Headers</li>
<li>Primary Buttons & Default</li>
<li>Calls to action</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<!-- /.nav-collapse -->
</nav>
</div>
Code available on codepen as well.
Any help would be appreciated,
Thank you
For your current problem, set .mega-dropdown-menu to either :
01 Using translate :
left: 50% /* instead of 0 */
transform: translateX(-50%);
02 Using margins (prefered solution IMO)
left: 0;
right: 0;
margin: 0 auto; /* Centers the element */
Not enough Rep to add a comment sorry.
I always found:
margin-right: auto;
margin-left: auto;
Does the trick without a need to set a left/right position.
You can also used the class "center-block" built in to Bootstrap 3 to apply this css as a class.
Personally I would recommend updating to Bootstrap 4, took me a while to make the leap but the flexgrid is such an improvement its worth it. Most of the classes are interchangeable to some degree, though in bootstrap 4 "center-block" is now "mx-auto"
Related
I am using bootstrap to create a webpage. I have a nabber at the top of the page and I would like my navbar-brand to be placed on the right and my nabber links to be place on the right. When I do this it seems to push the navbar links down and and means that the navbar and navbar-brand and not inline (as shown below)
Here is my html
<nav class="navbar navbar-expand-lg navbar-dark" id="mainNav">
<div class="container">
<a class="navbar-brand" href="#page-top">Navbar</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-end" id="navbarNav">
<ul class="navbar-nav mr-auto" id="myNavbar">
<li class="nav-item"><a class="nav-link" href="#">About</a></li>
<li class="nav-item"><a class="nav-link" href="#">Skills</a></li>
<li class="nav-item"><a class="nav-link" href="#">Portfolio</a></li>
<li class="nav-item"><a class="nav-link" href="#">Contact</a></li>
</ul>
</div>
</div>
</nav>
Here is my css
.navbar {
position: relative;
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
padding: 0.5rem 1rem; }
.navbar-nav .nav-link {
padding-right: 0;
padding-left: 0; }
.nav-item {
margin-bottom: -1px; }
nav #myNavbar li a {
float: right !important; }
.navbar-inverse {
border: none;
margin: 0;
background: transparent;
padding-left: 20px;
padding-bottom: 20px; }
.navbar-brand {
font-weight: 700;
padding-top: 0.3125rem;
padding-bottom: 0.3125rem;
margin-right: 1rem;
line-height: inherit;
white-space: nowrap;
display: inline-block; }
#mainNav .navbar-nav .nav-item .nav-link {
font-weight: 700;
font-size: 0.9rem;
display: inline-block; }
How do I fix this?
you omitted to open nav tag try using this code: <nav class="navbar navbar-expand-lg navbar-light bg-light"> hope this would work.
include this inside head tag:
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
paste this before closing body tag :
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>
Try to add wrapper <nav class="navbar"></nav> correctly. So your code will be like this:
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta1/dist/js/bootstrap.bundle.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-light">
<div class="container">
<a class="navbar-brand" href="#page-top">Navbar</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-end" id="navbarNav">
<ul class="navbar-nav mr-auto" id="myNavbar">
<li class="nav-item"><a class="nav-link" href="#">About</a></li>
<li class="nav-item"><a class="nav-link" href="#">Skills</a></li>
<li class="nav-item"><a class="nav-link" href="#">Portfolio</a></li>
<li class="nav-item"><a class="nav-link" href="#">Contact</a></li>
</ul>
</div>
</div>
</nav>
use like this..
var superfish = $('#st-navbar-desktop-menu-nav').superfish({
//add options here if required
});
/* Navbar desktop
-------------------------------------------------- */
.st-navbar-desktop-wrapper {
font-family: inherit;
font-size: 16px;
font-weight: 400;
position: absolute;
width: 100%;
padding: 0;
margin-top: 0;
margin-bottom: 0;
border-radius: 0;
z-index: 1030;
}
.st-navbar-desktop-fixed {
position: fixed;
top: 0;
}
.st-navbar-desktop {
position: relative;
height: 80px;
z-index: auto;
}
.st-navbar-desktop:before {
content: '';
display: block;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
}
/* Navbar desktop logo
-------------------------------------------------- */
.st-navbar-desktop-logo {
float: left;
margin: 26px 0 0;
}
.st-navbar-desktop-logo-link > img {
width: 112px;
height: 28px;
}
/* Navbar desktop menu
-------------------------------------------------- */
.st-navbar-desktop-menu {
float: right;
}
/* Navbar desktop menu superfish settings
-------------------------------------------------- */
.sf-menu, .sf-menu * {
margin: 0;
padding: 0;
list-style: none;
}
.sf-menu li {
position: relative;
}
.sf-menu ul {
position: absolute;
display: none;
top: 100%;
left: 0;
z-index: 99;
}
.sf-menu > li {
float: left;
}
.sf-menu li:hover > ul,
.sf-menu li.sfHover > ul {
display: block;
}
.sf-menu a {
display: block;
position: relative;
}
.sf-menu ul ul {
top: 0;
left: 100%;
}
/* Navbar desktop menu superfish custom
-------------------------------------------------- */
.sf-menu {
float: left;
}
.sf-menu ul {
min-width: 180px;
}
.sf-menu a {
padding: 28px 12px 29px 12px;
text-decoration: none;
zoom: 1;
}
.sf-menu li {
white-space: nowrap;
*white-space: normal;
-webkit-transition: background .2s;
transition: background .2s;
}
.sf-menu ul a {
padding: 11px 12px 12px 12px;
font-size: 13px;
}
.sf-menu li:hover,
.sf-menu li.sfHover {
-webkit-transition: none;
transition: none;
}
/*** Align right ***/
.sf-menu li.dropdown-right ul {
left: auto;
right: 0;
min-width: 150px;
}
.sf-menu li.dropdown-right a {
text-align: right;
zoom: 1;
}
.sf-menu li.dropdown-right ul ul {
right: 100%;
}
/* Navbar desktop menu superfish arrows
-------------------------------------------------- */
/*** Separacion chevron del texto en primer level ***/
.sf-arrows .sf-with-ul {
padding-right: 28px;
}
/*** Separacion chevron del texto en segundo level ***/
.sf-arrows ul .sf-with-ul {
padding-right: 38px;
}
/*** Separacion chevron del texto en segundo level dropdown right ***/
.sf-arrows li.dropdown-right ul .sf-with-ul {
padding-right: 12px;
padding-left: 38px;
}
/*** Generated arrows ***/
.sf-arrows .sf-with-ul:after {
content: '\f0d7';
font-family: 'FontAwesome';
position: absolute;
margin-top: 1px;
margin-left: 5px;
height: 0;
width: 0;
}
.sf-arrows > li > .sf-with-ul:focus:after,
.sf-arrows > li:hover > .sf-with-ul:after,
.sf-arrows > .sfHover > .sf-with-ul:after {
content: '\f0d8';
}
/*** Generated second arrows ***/
.sf-arrows ul .sf-with-ul:after {
content: '\f0da';
margin-left: 5px;
right: 20px;
}
.sf-arrows ul li > .sf-with-ul:focus:after,
.sf-arrows ul li:hover > .sf-with-ul:after,
.sf-arrows ul .sfHover > .sf-with-ul:after {
content: '\f0d7';
right: 23px;
}
/*** Generated second right arrows ***/
.sf-arrows li.dropdown-right ul .sf-with-ul:after {
float: left;
content: '\f0d9';
margin-right: 30px;
left: 10px;
}
.sf-arrows li.dropdown-right ul li > .sf-with-ul:focus:after,
.sf-arrows li.dropdown-right ul li:hover > .sf-with-ul:after,
.sf-arrows li.dropdown-right ul .sfHover > .sf-with-ul:after {
content: '\f0d7';
left: 10px;
}
/* Navbar desktop menu superfish last item
-------------------------------------------------- */
.sf-menu > li.no-padding-right > a {
padding-right: 0px;
}
/* Navbar desktop all styles
-------------------------------------------------- */
/*** Navbar desktop ***/
.st-navbar-desktop:before {
background-color: rgba(33,33,33,0.8);
}
/*** First level a ***/
.sf-menu a {
color: #ffffff;
}
.sf-menu a:hover,
.sf-menu a:focus {
color: #aaaaaa;
}
/*** Second level a ***/
.sf-menu ul a {
color: #cccccc;
}
.sf-menu ul a:hover,
.sf-menu ul a:focus {
color: #aaaaaa !important;
}
/*** Third level a ***/
.sf-menu ul ul a {
color: #cccccc;
}
.sf-menu ul ul a:hover,
.sf-menu ul ul a:focus {
color: #aaaaaa !important;
}
/*** First level li ***/
.sf-menu > li {
/*background: #BDD2FF;*/
}
.sf-menu > li:hover > a {
/*color: #676767;*/
}
/*** Second level li ***/
.sf-menu ul li {
background: #333333;
}
.sf-menu ul li:hover,
.sf-menu ul li.sfHover {
background: #3e3e3e;
}
/*** Third level li ***/
.sf-menu ul ul li {
background: #333333;
}
.sf-menu ul ul li:hover,
.sf-menu ul ul li.sfHover {
background: #3e3e3e;
}
/*** Levels li border top ***/
.sf-menu ul li {
border-top: 1px solid #494949;
}
.sf-menu ul ul li {
border-top: 1px solid #494949;
}
.sf-menu ul li:first-child {
border-top: 0;
}
/* Navbar desktop mas ajustes
-------------------------------------------------- */
.sf-menu > li:last-child > a {
padding-right: 0;
}
<div id="st-navbar-desktop-wrapper" class="st-navbar-desktop-wrapper st-navbar-desktop-fixed">
<div class="st-navbar-desktop">
<div class="container">
<div class="st-navbar-desktop-logo">
<a class="st-navbar-desktop-logo-link" style="text-decoration:none" title="Logo" href="index.html"><b>Navbar</b></a>
</div>
<nav class="st-navbar-desktop-menu" role="navigation">
<ul id="st-navbar-desktop-menu-nav" class="sf-menu">
<li>About</li>
<li>Skills
</li>
<li>Portfolio</li>
<li>Contact</li>
</ul>
</nav>
</div>
</div>
</div>
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.
This is only my second question here on Stack overflow so if there is any additional information you need or clarification needed on anything I say, please don't hesitate to ask.
I tried looking into this question and did find some people here with a similar issue, but none of the fixes that helped with them worked for me.
I am looking to have my navigation bar hidden when the max width doesn't exceed more than 767px. When it goes below that pixel amount, it should become a drop down menu that should collapse and expand when clicked by the button. This does not seem to be working for me.
My code is as follows
HTML
<header class="pull-center" id="masthead">
<nav class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<div id="img1"></div>
<div id="img2"></div>
<div id="img3"></div>
<div id="img4"></div>
<a class="btn btn-navbar" data-target=".nav-collapse" data-toggle="collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<a class="brand brand-ctg" href="#section-1"><span></span></a>
CTG
<span></span>
</a>
<div class="nav-collapse">
<ul class="nav">
<li>Demo Reel</li>
<li>Portfolio</li>
<li><a class="brand brand-ctg" href="#section-1"> <span></span></a></li>
<li>Contact</li>
<li>Blog</li>
</ul>
</div>
</div>
</div>
</nav>
</header>
CSS
#media (max-width: 767px) {
.nav-collapse .nav > li {
float: left !important;
}
.navbar .in .nav li {
display: block;
float: none;
width:100%;
}
.navbar .nav > li > a {
color: #fff !important;
float: none;
margin-right: -3px !important;
padding: 0 40px 10px !important;
text-decoration: none;
}
.navbar .nav {
margin-top: 0 !important;
position: fixed!important;
z-index: 1;
}
.nav-collapse .brand {
display: block !important;
}
.navbar .nav .active a,
.navbar .nav > li > a:hover,
.navbar .nav > .active > a:hover,
.navbar .nav > .active > a:focus {
background-color: transparent;
box-shadow: none;
color: #2d2e2d !important;
}
.navbar-fixed-top,
.navbar-fixed-bottom,
.navbar-static-top {
margin-left: -20px;
margin-right: -20px;
}
.navbar-fixed-top,
.navbar-fixed-bottom {
position: static;
}
.navbar-fixed-top {
margin-bottom: 30px;
}
.navbar-fixed-bottom {
margin-top: 30px;
}
.navbar-fixed-top .navbar-inner,
.navbar-fixed-bottom .navbar-inner {
padding: 5px;
}
.navbar .container {
width: auto;
padding: 0;
}
.navbar .brand {
margin: -10px 40px 0 0;
}
.nav-collapse {
clear: both;
}
.nav-collapse .nav {
float: none;
margin: 0 0 15px;
}
.nav-collapse .nav > li {
float: none;
}
.nav-collapse .nav > li > a {
margin-bottom: 2px;
}
.nav-collapse .nav > .divider-vertical {
display: none;
}
.nav-collapse .nav .nav-header {
color: #555555;
text-shadow: none;
}
.nav-collapse .nav > li > a,
.nav-collapse .dropdown-menu a {
padding: 9px 15px;
font-weight: bold;
color: #555555;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
}
.nav-collapse .btn {
padding: 4px 10px 4px;
font-weight: normal;
-webkit-border-radius: 0px;
-moz-border-radius: 0px;
border-radius: 0px;
}
.nav-collapse .dropdown-menu li + li a {
margin-bottom: 2px;
}
.nav-collapse .nav > li > a:hover,
.nav-collapse .dropdown-menu a:hover {
background-color: #f2f2f2;
}
.navbar-inverse .nav-collapse .nav > li > a,
.navbar-inverse .nav-collapse .dropdown-menu a {
color: #999999;
}
.navbar-inverse .nav-collapse .nav > li > a:hover,
.navbar-inverse .nav-collapse .dropdown-menu a:hover {
background-color: #111111;
}
.nav-collapse.in .btn-group {
margin-top: 5px;
padding: 0;
}
.nav-collapse .dropdown-menu {
position: static;
top: auto;
left: auto;
float: none;
display: none;
max-width: none;
margin: 0 15px;
padding: 0;
background-color: transparent;
border: none;
-webkit-border-radius: 0;
-moz-border-radius: 0;
border-radius: 0;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
}
.nav-collapse .open > .dropdown-menu {
display: block;
}
.nav-collapse .dropdown-menu:before,
.nav-collapse .dropdown-menu:after {
display: none;
}
.nav-collapse .dropdown-menu .divider {
display: none;
}
.nav-collapse .nav > li > .dropdown-menu:before, .nav-collapse .nav > li > .dropdown-menu:after {
display: none;
}
.nav-collapse .navbar-form,
.nav-collapse .navbar-search {
float: none;
padding: 15px 15px;
margin: 15px 0;
border-top: 1px solid #f2f2f2;
border-bottom: 1px solid #f2f2f2;
-webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 0 rgba(255, 255, 255, 0.1);
-moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 0 rgba(255, 255, 255, 0.1);
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 1px 0 rgba(255, 255, 255, 0.1);
}
.navbar-inverse .nav-collapse .navbar-form,
.navbar-inverse .nav-collapse .navbar-search {
border-top-color: #111111;
border-bottom-color: #111111;
}
.navbar .nav-collapse .nav.pull-right {
float: none;
margin-left: 0;
}
.nav-collapse,
.nav-collapse.collapse {
overflow: hidden;
height: 0;
background: #3b3b3b;
}
.navbar .btn-navbar {
background:url(http://www.colorthegrayscale.com/images/icons/hover-teal.png);
display: block;
width: 25px;
height: 50px;
position: fixed;
}
.navbar-static .navbar-inner {
padding-left: 10px;
padding-right: 10px;
}
.navbar .brand.brand-ctg span {
display: none !important;
}
EDIT 1
Tried to fix it, but still having my issue. I know some CSS is making the toggle button not work, I just can't seem to figure out what. For the sake of simply showing all my work in one place, you can find the test site here
You are overriding the bootstrap CSS styles when it is not need, so here is an example of a simple navbar based on twitter bootstrap:
Bootply DEMO
Snippet
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<!-- Fixed navbar -->
<div class="navbar navbar-default 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="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Project name</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active">Home
</li>
<li>About
</li>
<li>Contact
</li>
<li class="dropdown">
Dropdown <b class="caret"></b>
<ul class="dropdown-menu">
<li>Action
</li>
<li>Another action
</li>
<li>Something else here
</li>
<li class="divider"></li>
<li class="dropdown-header">Nav header</li>
<li>Separated link
</li>
<li>One more separated link
</li>
</ul>
</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
</div>
See Twitter Bootstrap Navbar Docs
EDIT: Based on your comment/updated question
here is your issue:
<a class="btn btn-navbar" data-target=".nav-collapse" data-toggle="collapse">
<!-- <span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span> -->
<a class="brand brand-ctg" href="#section-1"><span>CTG</span></a>
</a>
you are opening an a inside another a and that's invalid HTML. Here's how to fix it (according to Docs):
<button type="button" class="btn btn-navbar" data-target=".nav-collapse" data-toggle="collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="brand brand-ctg" href="#section-1"><span>CTG</span></a>
EDIT2:
I was looking and you are using an old version of bootstrap.css (v.2.2.1), the latest stable is 3.3.6, and you are missing the bootstrap.js (which make the menu to trigger when it is collapsed)
On my dashboard example I have the bootstrap navbar menu on top of the column_left menu as shown in code preview below
Update: This link has now be updated with new code from my Answer!
Code Preview Click Here
What I am trying to be able to do is have the navbar so its on the edge of the column left side bar and and open and close correct width also.
Currently the menu opens and closes under neath the navbar.
Question: How can I make my navbar so it on the edge of the sidebar
rather than on top and open and close with same width. I have tried to
put the navbar in side the content div but no luck.
HTML
<div id="column-left">
<ul id="menu">
<li>
<i class="fa fa-dashboard fa-fw"></i> <span>Dashboard</span>
</li>
<li>
<i class="fa fa-bar-chart"></i> <span>Single Link</span>
</li>
<li>
<a class="parent"><i class="fa fa-cog fa-fw"></i> <span>Multilevel Menu</span></a>
<ul>
<li>Link 1</li>
<li><a class="parent">Sub Multilevel Menu 1</a>
<ul>
<li>Sub Menu Link 1a</li>
<li>Sub Menu Link 1b</li>
</ul>
</li>
<li><a class="parent">Sub Multilevel Menu 2</a>
<ul>
<li>Sub Menu Link 2a</li>
<li>Sub Menu Link 2b</li>
<li>Sub Menu Link 2c</li>
</ul>
</li>
</ul>
</li><!-- System -->
</ul>
</div>
<div id="content">
<div class="main">
<div class="container-fluid">
<!-- Fixed navbar -->
<nav class="navbar navbar-default navbar-fixed-top navbar-shadow">
<div class="navbar-header">
<button aria-controls="navbar" aria-expanded="false" data-target="#navbar" data-toggle="collapse" class="navbar-toggle collapsed" type="button">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a type="button" id="button-menu" class="navbar-brand"><i class="fa fa-indent fa-lg"></i></a>
Project name
</div>
<div class="navbar-collapse collapse" id="navbar">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>About</li>
<li>Contact</li>
<li class="dropdown">
<a aria-expanded="false" aria-haspopup="true" role="button" data-toggle="dropdown" class="dropdown-toggle" href="#">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider" role="separator"></li>
<li class="dropdown-header">Nav header</li>
<li>Separated link</li>
<li>One more separated link</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Default</li>
<li>Static top</li>
<li class="active">Fixed top <span class="sr-only">(current)</span></li>
</ul>
</div><!--/.nav-collapse -->
</nav>
</div>
</div>
</div>
CSS
#import url(//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800&subset=latin,cyrillic-ext,greek-ext,vietnamese);
/* Global */
body {
/*height: 100%;*/
margin: 0;
/*min-height: 100% !important;*/
font-family: 'Open Sans', sans-serif;
overflow-x: hidden;
padding-top: 70px;
width: 100%;
background-color: #eee;
}
a,
a:hover,
a:focus {
cursor: pointer;
text-decoration: none;
}
tr:hover a.dashboard-user:after {
font-family: FontAwesome;
content: "\f044";
font-size: 14px;
}
/* fix for bootstrap hidden and visible */
span.hidden-xs, span.hidden-sm, span.hidden-md, span.hidden-lg {
display: inline;
}
/* Layout */
.container-fluid {
padding-left: 20px;
padding-right: 20px;
}
#content {
padding-bottom: 40px;
transition: all 0.3s;
}
/* Column Left */
#column-left {
width: 50px;
min-height: 100%;
background-color: #242424;
top: 0px;
position: fixed;
padding-top: 70px;
z-index: 10;
transition: all 0.3s;
}
#column-left:hover{
width: 250px;
}
#column-left + #content {
margin-left: 50px;
}
#column-left + #content + #footer {
margin-left: 50px;
}
#media (max-width: 767px) {
#column-left {
overflow: hidden;
display: none;
}
#column-left + #content {
margin-left: 0;
}
#column-left + #content + #footer {
margin-left: 0;
}
}
/* Column Left Active */
#column-left.active {
width: 235px;
display: block;
}
#media (min-width: 768px) {
#column-left.active {
overflow: auto;
}
#column-left.active + #content {
margin-left: 235px;
}
#column-left.active + #content + #footer {
margin-left: 235px;
}
}
#media (max-width: 767px) {
#column-left.active + #content {
position: relative;
left: 235px;
}
#column-left.active + #content + #footer {
position: relative;
left: 235px;
}
}
#column-left.active {
width: 235px;
}
#column-left.active #menu li i {
font-size: 14px;
}
#column-left.active #menu > li > a > span {
display: inline;
}
#column-left.active #menu > li > ul {
position: relative;
left: auto;
top: auto;
width: auto;
visibility: visible;
}
/* Top Navbar */
.menu {
background: #eeeeee none repeat scroll 0 0;
}
.navbar {
background-color: #fff !important;
border: 0 none;
border-radius: 0;
color: #666;
margin-bottom: 0;
}
.navbar.navbar-shadow {
box-shadow: 0 1px 0 0 rgba(0, 0, 0, 0.08), 0 2px 0 0 rgba(0, 0, 0, 0.02);
}
#button-menu {
display: inline-block;
cursor: pointer;
color: #6D6D6D;
}
#media (max-width: 640px) {
.navbar-brand {
font-size: 14px;
padding: 15px 7px;
}
}
.profile {
display: none;
}
#column-left.active .profile {
display: block;
padding-left: 15px;
border-bottom: 1px solid #2d2d2d;
padding-bottom: 25px;
}
.profile .media-left img {
border: 2px solid #888;
border-radius: 50%;
max-width: 40px;
}
/* Sidebar Menu */
#menu,
#menu ul,
#menu li {
padding: 0;
margin: 0;
min-height: 100%;
list-style: none;
}
#menu {
margin-bottom: 25px;
}
#menu > li {
position: relative;
}
#menu li a {
text-decoration: none;
display: block;
padding: 10px;
cursor: pointer;
color: #aaaaaa;
border-bottom: 1px solid #2d2d2d;
}
#menu li a i {
color: rgba(170, 170, 170, 0.7);
font-size: 16px;
}
#menu > li > a {
color: #aaaaaa;
font-size: 14px;
padding-left: 13px;
}
#menu > li > a:hover {
background-color: #444444;
}
#menu > li > a > span {
display: none;
margin-left: 8px;
}
#menu li li a {
border-bottom: none !important;
}
#menu li li a:hover {
color: #aaaaaa;
background-color: #1e1e1e;
}
/*
#menu li li a:before {
content: "\f101";
font-size: 14px;
font-family: FontAwesome;
margin-left: 10px;
margin-right: 10px;
transition: margin ease 0.5s;
}
*/
#menu li li a:hover:before {
margin-right: 20px;
}
#menu > li.active > a {
color: #aaaaaa;
background: #242424;
}
#menu li.active li a {
color: #aaaaaa;
}
#menu li li.active > a:last-child {
color: #aaaaaa;
}
#menu li li.active a:last-child:before {
margin-left: 20px;
margin-right: 10px;
}
#menu > li > ul {
position: absolute;
left: 50px;
top: 0px;
width: 210px;
background-color: #313131;
visibility: hidden;
}
#menu li ul {
overflow: hidden;
}
#menu li li a.parent:after, #column-left.active #menu > li a.parent:after {
font-family: FontAwesome;
content: "\f105";
float: right;
margin-right: 8px;
}
#menu li li.open > a.parent:after, #column-left.active #menu > li.open > a.parent:after {
font-family: FontAwesome;
content: "\f107";
float: right;
margin-right: 8px;
}
#menu li ul a {
padding-left: 20px;
}
#menu li li ul a {
padding-left: 40px;
}
#menu li li li ul a {
padding-left: 60px;
}
#menu li li li li ul a {
padding-left: 60px;
}
#menu li li li a.parent:after, #column-left.active #menu > li a.parent:after {
font-family: FontAwesome;
content: "\f105";
float: right;
margin-right: 8px;
}
#menu li li li.open > a.parent:after, #column-left.active #menu > li.open > a.parent:after {
font-family: FontAwesome;
content: "\f107";
float: right;
margin-right: 8px;
}
#menu li ul li a.parent:after, #column-left.active #menu > li ul li a.parent:after {
font-family: FontAwesome;
content: "\f105";
float: right;
margin-right: 8px;
}
#menu li ul li.open > a.parent:after, #column-left.active #menu > li ul li.open > a.parent:after {
font-family: FontAwesome;
content: "\f107";
float: right;
margin-right: 8px;
}
Problem solved.
Updated codepen preview
Click Here For Preview
The issue was have the navbar fixed so was on top all the time.
I have removed navbar-fixed-topand removed the padding-top 70px from body {}
Image
CSS
#import url(//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800&subset=latin,cyrillic-ext,greek-ext,vietnamese);
body {
margin: 0;
font-family: 'Open Sans', sans-serif;
overflow-x: hidden;
width: 100%;
background-color: #eee;
}
a,
a:hover,
a:focus {
cursor: pointer;
text-decoration: none;
}
tr:hover a.dashboard-user:after {
font-family: FontAwesome;
content: "\f044";
font-size: 14px;
}
/* fix for bootstrap hidden and visible */
span.hidden-xs, span.hidden-sm, span.hidden-md, span.hidden-lg {
display: inline;
}
/* Layout */
.container-fluid {
padding-left: 20px;
padding-right: 20px;
}
#content {
padding-bottom: 40px;
transition: all 0.3s;
}
/* Column Left */
#column-left {
width: 50px;
min-height: 100%;
background-color: #242424;
top: 0px;
position: fixed;
padding-top: 70px;
z-index: 10;
transition: all 0.3s;
}
#column-left:hover{
width: 250px;
}
#column-left + #content {
margin-left: 50px;
}
#column-left + #content + #footer {
margin-left: 50px;
}
#media (max-width: 767px) {
#column-left {
overflow: hidden;
display: none;
}
#column-left + #content {
margin-left: 0;
}
#column-left + #content + #footer {
margin-left: 0;
}
}
/* Column Left Active */
#column-left.active {
width: 235px;
display: block;
}
#media (min-width: 768px) {
#column-left.active {
overflow: auto;
}
#column-left.active + #content {
margin-left: 235px;
}
#column-left.active + #content + #footer {
margin-left: 235px;
}
}
#media (max-width: 767px) {
#column-left.active + #content {
position: relative;
left: 235px;
}
#column-left.active + #content + #footer {
position: relative;
left: 235px;
}
}
#column-left.active {
width: 235px;
}
#column-left.active #menu li i {
font-size: 14px;
}
#column-left.active #menu > li > a > span {
display: inline;
}
#column-left.active #menu > li > ul {
position: relative;
left: auto;
top: auto;
width: auto;
visibility: visible;
}
/* Top Navbar */
.menu {
background: #eeeeee none repeat scroll 0 0;
}
.navbar {
background-color: #fff !important;
border: 0 none;
border-radius: 0;
color: #666;
margin-bottom: 0;
}
.navbar.navbar-shadow {
box-shadow: 0 1px 0 0 rgba(0, 0, 0, 0.08), 0 2px 0 0 rgba(0, 0, 0, 0.02);
}
#button-menu {
display: inline-block;
cursor: pointer;
color: #6D6D6D;
}
#media (max-width: 640px) {
.navbar-brand {
font-size: 14px;
padding: 15px 7px;
}
}
.profile {
display: none;
}
#column-left.active .profile {
display: block;
padding-left: 15px;
border-bottom: 1px solid #2d2d2d;
padding-bottom: 25px;
}
.profile .media-left img {
border: 2px solid #888;
border-radius: 50%;
max-width: 40px;
}
/* Sidebar Menu */
#menu,
#menu ul,
#menu li {
padding: 0;
margin: 0;
min-height: 100%;
list-style: none;
}
#menu {
margin-bottom: 25px;
}
#menu > li {
position: relative;
}
#menu li a {
text-decoration: none;
display: block;
padding: 10px;
cursor: pointer;
color: #aaaaaa;
border-bottom: 1px solid #2d2d2d;
}
#menu li a i {
color: rgba(170, 170, 170, 0.7);
font-size: 16px;
}
#menu > li > a {
color: #aaaaaa;
font-size: 14px;
padding-left: 13px;
}
#menu > li > a:hover {
background-color: #444444;
}
#menu > li > a > span {
display: none;
margin-left: 8px;
}
#menu li li a {
border-bottom: none !important;
}
#menu li li a:hover {
color: #aaaaaa;
background-color: #1e1e1e;
}
/*
#menu li li a:before {
content: "\f101";
font-size: 14px;
font-family: FontAwesome;
margin-left: 10px;
margin-right: 10px;
transition: margin ease 0.5s;
}
*/
#menu li li a:hover:before {
margin-right: 20px;
}
#menu > li.active > a {
color: #aaaaaa;
background: #242424;
}
#menu li.active li a {
color: #aaaaaa;
}
#menu li li.active > a:last-child {
color: #aaaaaa;
}
#menu li li.active a:last-child:before {
margin-left: 20px;
margin-right: 10px;
}
#menu > li > ul {
position: absolute;
left: 50px;
top: 0px;
width: 210px;
background-color: #313131;
visibility: hidden;
}
#menu li ul {
overflow: hidden;
}
#menu li li a.parent:after, #column-left.active #menu > li a.parent:after {
font-family: FontAwesome;
content: "\f105";
float: right;
margin-right: 8px;
}
#menu li li.open > a.parent:after, #column-left.active #menu > li.open > a.parent:after {
font-family: FontAwesome;
content: "\f107";
float: right;
margin-right: 8px;
}
#menu li ul a {
padding-left: 20px;
}
#menu li li ul a {
padding-left: 40px;
}
#menu li li li ul a {
padding-left: 60px;
}
#menu li li li li ul a {
padding-left: 60px;
}
#menu li li li a.parent:after, #column-left.active #menu > li a.parent:after {
font-family: FontAwesome;
content: "\f105";
float: right;
margin-right: 8px;
}
#menu li li li.open > a.parent:after, #column-left.active #menu > li.open > a.parent:after {
font-family: FontAwesome;
content: "\f107";
float: right;
margin-right: 8px;
}
#menu li ul li a.parent:after, #column-left.active #menu > li ul li a.parent:after {
font-family: FontAwesome;
content: "\f105";
float: right;
margin-right: 8px;
}
#menu li ul li.open > a.parent:after, #column-left.active #menu > li ul li.open > a.parent:after {
font-family: FontAwesome;
content: "\f107";
float: right;
margin-right: 8px;
}
HTML
<div id="column-left">
<ul id="menu">
<li>
<i class="fa fa-dashboard fa-fw"></i> <span>Dashboard</span>
</li>
<li>
<i class="fa fa-bar-chart"></i> <span>Single Link</span>
</li>
<li>
<a class="parent"><i class="fa fa-cog fa-fw"></i> <span>Multilevel Menu</span></a>
<ul>
<li>Link 1</li>
<li><a class="parent">Sub Multilevel Menu 1</a>
<ul>
<li>Sub Menu Link 1a</li>
<li>Sub Menu Link 1b</li>
</ul>
</li>
<li><a class="parent">Sub Multilevel Menu 2</a>
<ul>
<li>Sub Menu Link 2a</li>
<li>Sub Menu Link 2b</li>
<li>Sub Menu Link 2c</li>
</ul>
</li>
</ul>
</li><!-- System -->
</ul>
</div>
<div id="content">
<!-- Fixed navbar -->
<nav class="navbar navbar-default navbar-shadow">
<div class="container-fluid">
<div class="navbar-header">
<button aria-controls="navbar" aria-expanded="false" data-target="#navbar" data-toggle="collapse" class="navbar-toggle collapsed" type="button">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a type="button" id="button-menu" class="navbar-brand"><i class="fa fa-indent fa-lg"></i></a>
Project name
</div>
<div class="navbar-collapse collapse" id="navbar">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>About</li>
<li>Contact</li>
<li class="dropdown">
<a aria-expanded="false" aria-haspopup="true" role="button" data-toggle="dropdown" class="dropdown-toggle" href="#">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider" role="separator"></li>
<li class="dropdown-header">Nav header</li>
<li>Separated link</li>
<li>One more separated link</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Default</li>
<li>Static top</li>
<li class="active">Fixed top <span class="sr-only">(current)</span></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<div class="container-fluid">
</div>
</div>
</div>
I have a CMS-generated main-nav menu with one sub-menu. Both menus are standard ul tags with a class of “navCMSListMenuUL” which is then styled in my CSS accordingly. The issue is that on a:hover, the container expands to accommodate the newly displayed sub-nav ul.
I would like for the sub-nav to go outside of the container and flow at a higher z-index than any elements beneath the container. There are a couple of other things that I would like to clean up in this nav, but those are ancillary to the sub-nav flow. I have created a reduced test-case in Codepen # http://codepen.io/patrickTheWizard/pen/ZGWKYX .
<nav class="navigation">
<ul id="menuElem" class="navCMSListMenuUL">
<li class="navCMSListMenuLI">
<a class="navCMSListMenuLink" href="#">Home</a>
</li>
<li class="navCMSListMenuLI">
<a class="navCMSListMenuLink" href="#">About Us</a>
</li>
<li class="navCMSListMenuLI">
<a class="navCMSListMenuLink" href="#">Calendar</a>
</li>
<li class="navCMSListMenuHighlightedLI noseparator">
<a class="navCMSListMenuLinkHighlighted" href="#">Members</a>
<ul class="navCMSListMenuUL">
<li class="navCMSListMenuLI">
<a class="navCMSListMenuLink" href="#">Become a Member</a>
</li>
<li class="navCMSListMenuLI">
<a class="navCMSListMenuLink" href="#">Board Meetings</a>
</li>
<li class="navCMSListMenuLI">
<a class="navCMSListMenuLink" href="#">Committees</a>
</li>
<li class="navCMSListMenuLI">
<a class="navCMSListMenuLink" href="#">Current Members</a>
</li>
<li class="navCMSListMenuLI">
<a class="navCMSListMenuLink" href="#">Member Benefits</a>
</li>
<li class="navCMSListMenuLI noseparator">
<a class="navCMSListMenuLink" href="#">Statistics & Data</a>
</li>
</ul>
</li>
</ul>
/* #01-Header/Nav# */
nav.navigation {
clear: both;
/* background-color: #3c3c3c; */
overflow: visible;
/* padding: 15px; */
/* border-top: 6px solid #2a8cec; */
/* margin-bottom: 30px; */
}
ul#menuElem {
text-align: center;
background-color: #3c3c3c;
border-top: 6px solid #2a8cec;
margin-bottom: 30px;
}
ul#menuElem li {
display: inline-block;
margin: 16px 0 15px 0;
}
ul#menuElem a {
color: #fff;
text-decoration: none;
padding: 15px 35px;
font-weight: 600;
text-transform: uppercase;
border-right: 1px solid;
margin: 15px 0;
margin-left: -4px;
}
ul#menuElem a:hover {
background-color: #2a8cec;
}
ul#menuElem li ul {
display: none;
width: 100%;
float: left;
}
ul#menuElem li:hover ul {
display: block;
}
ul#menuElem ul li {
display: block;
}
OK, you when doing menu-like code, you are going to have styles that override each other (multiple nested UL, LI and A).
It's good practice to include the ">" element in your style sheets, which limits the scope of your query to direct children.
I have edited your code a bit, mainly by introducing that direct child rule (>). I also made the sub menu absolute positioned to it's parent, meaning you will not have the sub menu push your main menu to grow large.
Here is your code pen.
And the code:
/* #01-Header/Nav# */
nav.navigation {
clear: both;
/* background-color: #3c3c3c; */
overflow: visible;
/* padding: 15px; */
/* border-top: 6px solid #2a8cec; */
/* margin-bottom: 30px; */
}
ul#menuElem {
text-align: center;
background-color: #3c3c3c;
border-top: 6px solid #2a8cec;
margin-bottom: 30px;
}
ul#menuElem > li {
display: inline-block;
position: relative;
margin: 16px 0 15px 0;
}
ul#menuElem > li > a {
color: #fff;
text-decoration: none;
padding: 15px 35px;
font-weight: 600;
text-transform: uppercase;
border-right: 1px solid;
margin: 15px 0;
margin-left: -4px;
}
ul#menuElem > li > a:hover {
background-color: #2a8cec;
}
ul#menuElem > li > ul {
display: none;
width: 100%;
float: left;
}
ul#menuElem > li:hover ul {
display: block;
top: 30px;
right: 0px;
position: absolute;
background: #FFF;
padding: 0px;
margin: 0px;
}
ul#menuElem > li:hover > ul > li{
margin: 0px;
padding: 0px;
list-style: none;
text-align: left;
padding: 5px;
line-height: 30px;
border-bottom: solid 1px #dedede;
}
ul#menuElem > li:hover > ul > li > a{
text-decoration: none;
color: inherit;
}
ul#menuElem > li:hover > ul > li:hover {
background: #000;
color: #FFF;
}
ul#menuElem > ul > li {
display: block;
}