I have a bootstrap navbar which utilizes drop down links. Currently it looks as follows:
The green part is the actual navbar and the grey part is the dropdown you get when you click any of the links.
I would like to space out the links in my nav bar so that they are evenly spaced with some padding on the left and right, kind of like this:
Right now here is how my code is structured:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<style>
.navbar {
background-color: #007953;
font-family: Arial;
text-transform: uppercase;
}
.nav.navbar-nav li a {
color: white;
}
.navbar-default .navbar-nav > li > a:hover, .navbar-default .navbar-nav > li > a:focus {
background-color: #007953;
color: white;
}
.navbar-default .navbar-nav > .open > a, .navbar-default .navbar-nav > .open > a:focus, .navbar-default .navbar-nav > .open > a:hover {
color: white;
background-color: #007953;
}
.nav > li.dropdown.open {
position: static;
}
.nav > li.dropdown.open .dropdown-menu {
display:table; width: 100%; text-align: center; left:0; right:0;
}
.dropdown-menu>li {
display: table-cell;
}
.dropdown-menu {
min-width: 200px;
background-color: #49565A;
}
.dropdown-menu.columns-2 {
min-width: 400px;
background-color: #49565A;
}
/* background-color here controls background of sub menu*/
.dropdown-menu.columns-3 {
min-width: 600px;
background-color: #49565A;
font-family: Arial;
text-transform: capitalize;
}
.dropdown-menu li a {
padding: 5px 15px;
font-weight: 300;
text-align: left;
}
/* color tag here controls color of sub menu item's text*/
.multi-column-dropdown {
list-style: none;
}
.multi-column-dropdown li a {
display: block;
clear: both;
line-height: 1.428571429;
color: #333;
white-space: normal;
}
.multi-column-dropdown li a:hover {
text-decoration: none;
color: yellow;
}
.caret {
color: #9CCB3B;
}
#media (max-width: 767px) {
.dropdown-menu.multi-column {
min-width: 240px !important;
overflow-x: hidden;
}
}
</style>
</head>
<body>
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!--/.navbar-header-->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="dropdown">
Three Column <b class="caret" ></b>
<ul class="dropdown-menu multi-column columns-3">
<div class="row">
<div class="col-sm-4">
<ul class="multi-column-dropdown">
<li>Action</li>
<li class="divider"></li>
<li>Another action</li>
<li class="divider"></li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
<li class="divider"></li>
<li>One more separated link</li>
</ul>
</div>
<div class="col-sm-4">
<ul class="multi-column-dropdown">
<li>Action</li>
<li class="divider"></li>
<li>Another action</li>
<li class="divider"></li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
<li class="divider"></li>
<li>One more separated link</li>
</ul>
</div>
<div class="col-sm-4">
<ul class="multi-column-dropdown">
<li>Action</li>
<li class="divider"></li>
<li>Another action</li>
<li class="divider"></li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
<li class="divider"></li>
<li>One more separated link</li>
</ul>
</div>
</div>
</ul>
</li>
<li class="dropdown">
Three Column <b class="caret" ></b>
<ul class="dropdown-menu multi-column columns-3">
<div class="row">
<div class="col-sm-4">
<ul class="multi-column-dropdown">
<li>Action</li>
<li class="divider"></li>
<li>Another action</li>
<li class="divider"></li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
<li class="divider"></li>
<li>One more separated link</li>
</ul>
</div>
<div class="col-sm-4">
<ul class="multi-column-dropdown">
<li>Action</li>
<li class="divider"></li>
<li>Another action</li>
<li class="divider"></li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
<li class="divider"></li>
<li>One more separated link</li>
</ul>
</div>
<div class="col-sm-4">
<ul class="multi-column-dropdown">
<li>Action</li>
<li class="divider"></li>
<li>Another action</li>
<li class="divider"></li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
<li class="divider"></li>
<li>One more separated link</li>
</ul>
</div>
</div>
</ul>
</li>
<li class="dropdown">
Three Column <b class="caret" ></b>
<ul class="dropdown-menu multi-column columns-3">
<div class="row">
<div class="col-sm-4">
<ul class="multi-column-dropdown">
<li>Action</li>
<li class="divider"></li>
<li>Another action</li>
<li class="divider"></li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
<li class="divider"></li>
<li>One more separated link</li>
</ul>
</div>
<div class="col-sm-4">
<ul class="multi-column-dropdown">
<li>Action</li>
<li class="divider"></li>
<li>Another action</li>
<li class="divider"></li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
<li class="divider"></li>
<li>One more separated link</li>
</ul>
</div>
<div class="col-sm-4">
<ul class="multi-column-dropdown">
<li>Action</li>
<li class="divider"></li>
<li>Another action</li>
<li class="divider"></li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
<li class="divider"></li>
<li>One more separated link</li>
</ul>
</div>
</div>
</ul>
</li>
</ul>
</div>
<!--/.navbar-collapse-->
</nav>
<!--/.navbar-->
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</body>
</html>
How can I achieve this without breaking any of the drop down functionality which I have implemented?
I've added some modifications for you code. Hope this will work for you.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<style>
.navbar {
background-color: #007953;
font-family: Arial;
text-transform: uppercase;
}
.dropdown{
margin-right:140px;
margin-left:22px;
}
.nav.navbar-nav li a {
color: white;
}
..nav .navbar-nav{
width:900px !important;
}
.nav .navbar-nav .dropdown{
margin-right:200px;
}
.navbar-default .navbar-nav > li > a:hover, .navbar-default .navbar-nav > li > a:focus {
background-color: #007953;
color: white;
}
.navbar-default .navbar-nav > .open > a, .navbar-default .navbar-nav > .open > a:focus, .navbar-default .navbar-nav > .open > a:hover {
color: white;
background-color: #007953;
}
.nav > li.dropdown.open {
position: static;
}
.nav > li.dropdown.open .dropdown-menu {
display:table; width: 100%; text-align: center; left:0; right:0;
}
.dropdown-menu>li {
display: table-cell;
}
.dropdown-menu {
min-width: 200px;
background-color: #49565A;
}
.dropdown-menu.columns-2 {
min-width: 400px;
background-color: #49565A;
}
/* background-color here controls background of sub menu*/
.dropdown-menu.columns-3 {
min-width: 600px;
background-color: #49565A;
font-family: Arial;
text-transform: capitalize;
}
.dropdown-menu li a {
padding: 5px 15px;
font-weight: 300;
text-align: left;
}
/* color tag here controls color of sub menu item's text*/
.multi-column-dropdown {
list-style: none;
}
.multi-column-dropdown li a {
display: block;
clear: both;
line-height: 1.428571429;
color: #333;
white-space: normal;
}
.multi-column-dropdown li a:hover {
text-decoration: none;
color: yellow;
}
.caret {
color: #9CCB3B;
}
#media (max-width: 767px) {
.dropdown-menu.multi-column {
min-width: 240px !important;
overflow-x: hidden;
}
}
</style>
</head>
<body>
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!--/.navbar-header-->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="dropdown">
Three Column <b class="caret" ></b>
<ul class="dropdown-menu multi-column columns-3">
<div class="row">
<div class="col-sm-2">
<ul class="multi-column-dropdown">
<li>Action</li>
<li class="divider"></li>
<li>Another action</li>
<li class="divider"></li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
<li class="divider"></li>
<li>One more separated link</li>
</ul>
</div>
<div class="col-sm-2">
<ul class="multi-column-dropdown">
<li>Action</li>
<li class="divider"></li>
<li>Another action</li>
<li class="divider"></li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
<li class="divider"></li>
<li>One more separated link</li>
</ul>
</div>
<div class="col-sm-2">
<ul class="multi-column-dropdown">
<li>Action</li>
<li class="divider"></li>
<li>Another action</li>
<li class="divider"></li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
<li class="divider"></li>
<li>One more separated link</li>
</ul>
</div>
</div>
</ul>
</li>
<li class="dropdown">
Three Column <b class="caret" ></b>
<ul class="dropdown-menu multi-column columns-3">
<div class="row">
<div class="col-sm-4">
<ul class="multi-column-dropdown">
<li>Action</li>
<li class="divider"></li>
<li>Another action</li>
<li class="divider"></li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
<li class="divider"></li>
<li>One more separated link</li>
</ul>
</div>
<div class="col-sm-4">
<ul class="multi-column-dropdown">
<li>Action</li>
<li class="divider"></li>
<li>Another action</li>
<li class="divider"></li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
<li class="divider"></li>
<li>One more separated link</li>
</ul>
</div>
<div class="col-sm-4">
<ul class="multi-column-dropdown">
<li>Action</li>
<li class="divider"></li>
<li>Another action</li>
<li class="divider"></li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
<li class="divider"></li>
<li>One more separated link</li>
</ul>
</div>
</div>
</ul>
</li>
<li class="dropdown">
Three Column <b class="caret" ></b>
<ul class="dropdown-menu multi-column columns-3">
<div class="row">
<div class="col-sm-4">
<ul class="multi-column-dropdown">
<li>Action</li>
<li class="divider"></li>
<li>Another action</li>
<li class="divider"></li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
<li class="divider"></li>
<li>One more separated link</li>
</ul>
</div>
<div class="col-sm-4">
<ul class="multi-column-dropdown">
<li>Action</li>
<li class="divider"></li>
<li>Another action</li>
<li class="divider"></li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
<li class="divider"></li>
<li>One more separated link</li>
</ul>
</div>
<div class="col-sm-4">
<ul class="multi-column-dropdown">
<li>Action</li>
<li class="divider"></li>
<li>Another action</li>
<li class="divider"></li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
<li class="divider"></li>
<li>One more separated link</li>
</ul>
</div>
</div>
</ul>
</li>
</ul>
</div>
<!--/.navbar-collapse-->
</nav>
<!--/.navbar-->
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</body>
</html>
Related
I included this plugin to have my Bootstrap Nav a submenu. My problem is how can I align the submenu to its parent. I need to move it down a little.
I created a CSS like this:
#header-menu-nav .dropdown-menu li ul { margin-top: -27px !important; }
And it's working fine. My problem is in the responsive part. It also affected.
Here's my code in simple HTML:
<ul class="nav navbar-nav" id="header-menu-nav">
<li>
New
<ul class="dropdown-menu">
<li>TEST</li>
<li>TEST</li>
<li>TEST</li>
<li>TEST</li>
<li>TEST</li>
</ul>
</li>
<li>Furniture</li>
<li>Lighting</li>
<li>Kitchen
<ul class="dropdown-menu">
<li>Action
<ul class="dropdown-menu">
<li>Action</li>
<li>Something else here</li>
<li>One more link</li>
<li>Menu item 1</li>
<li>Menu item 2</li>
<li>Menu item 3</li>
</ul>
</li>
<li>Another action</li>
<li>Something else here</li>
<li>Separated link</li>
<li>One more separated link
<ul class="dropdown-menu">
<li>Another action</li>
<li>A long sub menu
<ul class="dropdown-menu">
<li>Action</li>
<li>Something else here</li>
<li>One more link</li>
<li>Menu item 1</li>
<li>Menu item 2</li>
<li>Menu item 3</li>
</ul>
</li>
<li>Another link</li>
<li>One more link</li>
</ul>
</li>
</ul>
</li>
<li>Bath</li>
<li>Interior Goods</li>
<li>Gifts</li>
<li>Outlet</li>
</ul>
Can you help me. Is there a proper way in doing this? Im not really good enough in CSS.
try this.
#header-menu-nav .dropdown-menu li{
position: relative;
}
#header-menu-nav .dropdown-menu li ul{
position: absolute;
top:0;
left: 100%;
}
and remove the margin-top:-27px;
I want to implement this functionality:
.
Here is a fiddle of what I have so far: https://jsfiddle.net/vvevq2c3/
Below is the code I have tried without any luck:
ATTEMPT 1
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"> Personal
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<div class="row">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li>Separated link</li>
<li>One more separated link</li>
<li>Separated link</li>
</div>
</ul>
</li>
</ul>
ATTEMPT 2
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Personal
<span class="caret"></span>
</a>
<div class="row">
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li>Separated link</li>
<li>One more separated link</li>
<li>Separated link</li>
</ul>
</div>
</li>
</ul>
ATTEMPT 3
<div class="row">
<ul class="dropdown-menu">
<div class="span6">
<div class="mycontent-left">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
</div>
</div>
<div class="span6">
<div class="mycontent-right">
<li>Separated link</li>
<li>One more separated link</li>
<li>Separated link</li>
</div>
</div>
</div>
</ul>
Does anyone have ideas on how to achieve this functionality?
UPDATE
With the help of the answers, I was able to align the dropdown menu content horizontally. Here is the modified code:
<!doctype html>
<html>
<head>
<title> Paypal </title>
<link rel = "stylesheet" href = "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel = "stylesheet" href = "../css/paypal.css">
<script src = "https://code.jquery.com/jquery-2.1.4.min.js"> </script>
<script src = "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"> </script>
</head>
<body>
<nav class="navbar navbar-default">
<div class="navbar-header">
<a class="navbar-brand" href="#">Paypal </a>
</div>
<div class="container-fluid">
<ul class="nav navbar-nav">
<li class="dropdown megamenu">
Personal <span class="caret"></span>
<div class="dropdown-menu row">
<ul class="list-unstyled col-lg-12 col-sm-12" role="menu">
<ul class="col-lg-4 col-sm-6 list-unstyled">
<li >Pay on eBay</li>
<li>Pay on websites</li>
</ul>
<ul class="col-lg-4 col-sm-6 list-unstyled">
<li>Pay in apps</li>
<li>Pay in stores</li>
</ul>
<ul class="col-lg-4 col-sm-6 list-unstyled">
<li>More ways to use us</li>
</ul>
</ul>
</div>
</li>
</ul>
<ul class="nav navbar-nav">
<li class="dropdown megamenu">
Business <span class="caret"></span>
<div class="dropdown-menu row">
<ul class="list-unstyled col-lg-12 col-sm-12" role="menu">
<ul class="col-lg-4 col-sm-6 list-unstyled">
<li >All business solutions</li>
<li>Get paid on your website </li>
</ul>
<ul class="col-lg-4 col-sm-6 list-unstyled">
<li>Get oaid on the go </li>
<li>Get paid in your store </li>
</ul>
<ul class="col-lg-4 col-sm-6 list-unstyled">
<li>Get paid in your app </li>
<li>Email an invoice </li>
</ul>
</ul>
</div>
</li>
</ul>
<ul class="nav navbar-nav">
<li class="dropdown megamenu">
Send <span class="caret"></span>
<div class="dropdown-menu row" class="col-lg-6">
<div class="form-group">
<input type="email" class="form-control" id="exampleInputEmail1" placeholder="Please enter your email or number">
</div>
<div class="input-group">
<input type="text" class="form-control" aria-label="...">
<div class="input-group-btn">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Action <span class="caret"></span></button>
<ul class="dropdown-menu dropdown-menu-right">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li role="separator" class="divider"></li>
<li>Separated link</li>
</ul>
</div><!-- /btn-group -->
</div><!-- /input-group -->
</div><!-- /.col-lg-6 -->
</nav>
<script src = "../javascript/Paypal.js"> </script>
</body>
</html>
paypal.css
#media screen and (min-width: 768px) {
.megamenu ul {
padding-bottom:15px;
}
.megamenu ul:not(:last-of-type) {
border-right:1px solid #ccc;
}
.megamenu > .dropdown-menu {
min-width:800px;
}
.megamenu ul {
padding-bottom:15px;
}
}
ul {
margin-top: 0.5%;
}
#exampleInputEmail1 {
width : 50%;
margin-left: 3%;
margin-top: 2%;
}
.input-group {
width : 50%;
margin-left: 3%;
margin-bottom: 2%;
}
paypal.js
var paypal = (function ($) {
'use strict';
return {
stopPaypal : function () {
$('.dropdown-menu').on('click', function (e) {
e.stopPropagation();
});
}
};
}(jQuery));
paypal.stopPaypal();
You can try something like this using the Bootstrap col-* so that the menu UL's float left on larger screens...
http://codeply.com/go/QYaBcXNX7J
Also, your ATTEMPT 3 uses span3 which is not a Bootstrap 3 class.
This might help you get closer to what you're trying to accomplish.
.navbar-custom {
border-bottom: none;
}
.navbar-custom .navbar-nav > li > a,
.navbar-header a.navbar-brand {
color: #009cde;
}
.navbar-custom .navbar-nav .open .dropdown-menu .dropdown-header {
color: #009cde;
}
.navbar-custom .menu-large {
position: static;
}
.navbar-custom .megamenu {
padding: 20px 0px;
width: 100%;
}
.navbar-custom .megamenu > li > ul {
padding: 0;
margin: 0;
text-align: center;
}
.navbar-custom .megamenu > li > ul:not(:last-child) {
border-right: 1px solid #fff;
}
.navbar-custom .megamenu > li > ul > li {
list-style: none;
display: block;
}
.navbar-custom .megamenu > li > ul > li > a {
display: inline-block;
padding: 3px 20px;
clear: both;
font-weight: normal;
line-height: 1.428571429;
color: #fff;
white-space: normal;
}
.navbar-custom .megamenu> li ul > li > a:hover,
.navbar-custom .megamenu> li ul > li > a:focus {
text-decoration: none;
color: #009cde;
background: #fff;
width: 100%;
}
.navbar-custom .nav > li.dropdown.open .dropdown-menu {
background: #009cde;
}
.navbar-custom .caret-up {
width: 0;
height: 0;
border-left: 4px solid rgba(0, 0, 0, 0);
border-right: 4px solid rgba(0, 0, 0, 0);
border-bottom: 4px solid;
display: inline-block;
margin-left: 2px;
vertical-align: middle;
}
.navbar-custom .navbar-toggle .icon-bar {
background: #266080;
}
#media (max-width: 768px) {
.navbar-custom .megamenu {
margin-left: 0;
margin-right: 0;
}
.navbar-custom .megamenu > li > ul > li > a {
padding: 6px 20px;
margin-bottom: 3px;
width: 100%;
}
.navbar-custom .megamenu > li > ul:not(:last-child) {
border-right: none;
}
.navbar-custom .megamenu > li > ul {
border: none;
margin: 10px auto;
text-align: left;
border-bottom: 1px solid #fff;
}
}
<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.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div class="navbar navbar-custom navbar-static-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="#">Brand</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>Home
</li>
<li class="dropdown menu-large "> Things <span class="caret"></span>
<ul class="dropdown-menu megamenu">
<li class="col-sm-12 ">
<ul class="col-sm-4">
<li>Action
</li>
<li>Another action
</li>
<li>Something else here
</li>
</ul>
<ul class="col-sm-4">
<li>Action
</li>
<li>Another action
</li>
<li>Something else here
</li>
</ul>
<ul class="col-sm-4">
<li>Action
</li>
<li>Another action
</li>
<li>Something else here
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
<div class="well">
<h1>Stuff</h1>
</div>
http://www.bootply.com/jwGIUdSuHM
I am using Bootstrap, and I have two menus at the top. Once I make my window narrow, my "responsive view" looks like this when I click on My Account. Notice the overlapping options (not good). How can I fix that?
I've tried setting this to 700 instead of approximately 300 pixels:
.navbar-fixed-top .navbar-collapse, .navbar-fixed-bottom .navbar-collapse { max-height: 700px; }
... and although the problem is gone, it doesn't quite do it for me, because it makes my menu stretch way to long on a phone. So how can I fix that ugly overlap while keeping my menu the same height?
CSS
body { margin-top: 125px; }
h1 {text-transform:uppercase;}
/* Header Nav*/
#faves, #cart {border:none;}
#nav {text-transform:uppercase;}
.multi-col-4 {width:820px;}
.multi-col-2 {width:400px;}
#media (max-width: 890px) {
body { margin-top: 65px; }
/* Nav*/
.multi-col {width:100%;}
}
HTML
<form>
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#nav" aria-expanded="false" aria-controls="nav"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button>
<button id="faves" type="button" class="navbar-toggle btn-link btn-lg"> <span class="sr-only">Favorites</span> <span class="glyphicon glyphicon-star" aria-hidden="true"></span> </button>
<button id="cart" type="button" class="navbar-toggle btn-link btn-lg"> <span class="sr-only">Shopping Cart</span> <span class="glyphicon glyphicon-shopping-cart" aria-hidden="true"></span> </button>
<a class="navbar-brand" href="#">Logo</a> </div>
<!-- end navbar-header -->
<div id="nav" class="navbar-collapse collapse">
<div id="navTop" class="navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown hidden-xs"> <span class="glyphicon glyphicon-shopping-cart" aria-hidden="true"></span> Cart (2) <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Something else here</li>
<li class="divider"></li>
<li>View Cart</li>
</ul>
</li>
<li class="dropdown hidden-xs"> <span class="glyphicon glyphicon-star" aria-hidden="true"></span> Favorites (6) <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Something else here</li>
<li class="divider"></li>
<li>View All Favorites</li>
</ul>
</li>
<li> Option a </li>
<li class="dropdown"> My Account <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>
<div class="multi-col multi-col-4">
<ul class="list-unstyled col-md-4" role="menu">
<li class="dropdown-header">Option 2</li>
<li>Option 3</li>
<li>Option 4</li>
<li>Option 5</li>
</ul>
<ul class="list-unstyled col-md-4" role="menu">
<li class="dropdown-header">Option 6</li>
<li>Option 7</li>
<li>Option 8</li>
<li>Option 9</li>
<li>Option 10</li>
<li>Option 11</li>
<li>Option 12</li>
<li>Option 13</li>
</ul>
<ul class="list-unstyled col-md-4" role="menu">
<li class="dropdown-header">Option 14</li>
<li>Option 15</li>
<li>Option 16</li>
<li>Option 17</li>
<li>Option 18</li>
<li>Option 19</li>
<li>Option 20</li>
</ul>
<ul class="list-unstyled col-md-4" role="menu">
<li class="dropdown-header">Option 21</li>
<li>Option 21</li>
<li>Option 22</li>
<li>Option 23</li>
<li>Option 24</li>
<li>Option 25</li>
</ul>
</div>
</li>
</ul>
</li>
</ul>
</div>
<div id="navBottom" class="navbar-collapse">
<ul class="nav navbar-nav">
<li class="dropdown"> Option b <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>
<div class="multi-col multi-col-4">
<ul class="list-unstyled col-md-4" role="menu">
<li class="dropdown-header">Another action</li>
<li>Another action</li>
<li>Another action</li>
<li>Another action</li>
<li>Another action</li>
<li>Another action</li>
<li>Another action</li>
<li>Another action</li>
</ul>
<ul class="list-unstyled col-md-4" role="menu">
<li class="dropdown-header">Another action</li>
<li>Another action</li>
<li>Another action</li>
</ul>
<ul class="list-unstyled col-md-4" role="menu">
<li class="dropdown-header">Other Products</li>
<li>Action</li>
<li>Another action</li>
</ul>
<ul class="list-unstyled col-md-4" role="menu">
<li class="dropdown-header">Another action</li>
<li>Another action</li>
<li>Another action</li>
</ul>
</div>
</li>
</ul>
</li>
<li class="dropdown"> Option c <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Another action</li>
<li>Another action</li>
<li>Another action</li>
<li>Another action</li>
<li>Another action</li>
</ul>
</li>
<li class="dropdown"> Option d <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Another action</li>
<li>Another action</li>
</ul>
</li>
<li class="dropdown"> Option e <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>
<div class="multi-col multi-col-2">
<ul class="list-unstyled col-md-4" role="menu">
<li class="dropdown-header">Account</li>
<li>Another action</li>
<li>Something else here</li>
</ul>
<ul class="list-unstyled col-md-4" role="menu">
<li class="dropdown-header">Tools</li>
<li>Action</li>
<li>Another action</li>
</ul>
</div>
</li>
</ul>
</li>
<li class="dropdown"> Option f <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>
<div class="multi-col multi-col-2">
<ul class="list-unstyled col-md-4" role="menu">
<li class="dropdown-header">Account</li>
<li>Another action</li>
<li>Something else here</li>
</ul>
<ul class="list-unstyled col-md-4" role="menu">
<li class="dropdown-header">Tools</li>
<li>Action</li>
<li>Another action</li>
</ul>
</div>
</li>
</ul>
</li>
<li class="dropdown"> Option g <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Another action</li>
<li>Another action</li>
<li>Another action</li>
<li>Another action</li>
<li>Another action</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="active">Another action</li>
</ul>
</div>
</div>
<!-- end nav -->
</div>
<!-- end container-fluid -->
</nav>
</form>
I got it resolved with these two lines:
.navbar-fixed-top .navbar-collapse, .navbar-fixed-bottom .navbar-collapse { max-height: none; }
#nav {max-height:400px;}
I'm looking how to convert dropdown menu on bootstrap for no JS user.
I already see its possible in full CSS but I'm not very friendly with CSS ...
Any one can help me ?
There is a possibility.
Download this Bootstrap
Implement this code jsFiddle here
HTML
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container-fluid">
<a data-target=".nav-collapse" data-toggle="collapse" class="btn btn-navbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
Project name
<div class="nav-collapse">
<ul class="nav">
<li class="active">Home</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li class="dropdown">
<a data-toggle="dropdown" class="dropdown-toggle" href="#">Dropdown <b class="caret"></b></a>
<ul class="dropdown-menu">
<li>
2-level Dropdown <i class="icon-arrow-right"></i>
<ul class="dropdown-menu sub-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li class="nav-header">Nav header</li>
<li>Separated link</li>
<li>One more separated link</li>
</ul>
</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li class="nav-header">Nav header</li>
<li>Separated link</li>
<li>One more separated link</li>
</ul>
</li>
</ul>
<form action="" class="navbar-search pull-left">
<input type="text" placeholder="Search" class="search-query span2">
</form>
<ul class="nav pull-right">
<li>Link</li>
<li class="divider-vertical"></li>
<li class="dropdown">
<a class="#" href="#">Menu</a>
</li>
</ul>
</div><!-- /.nav-collapse -->
</div>
</div>
</div>
<hr>
<ul class="nav nav-pills">
<li class="active">Regular link</li>
<li class="dropdown">
Dropdown <b class="caret"></b>
<ul class="dropdown-menu" id="menu1">
<li>
2-level Menu <i class="icon-arrow-right"></i>
<ul class="dropdown-menu sub-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li class="nav-header">Nav header</li>
<li>Separated link</li>
<li>One more separated link</li>
</ul>
</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
</ul>
</li>
<li class="dropdown">
Menu
</li>
<li class="dropdown">
Menu
</li>
</ul>
CSS
body {
padding-top: 60px;
padding-bottom: 40px;
}
.sidebar-nav {
padding: 9px 0;
}
.dropdown-menu .sub-menu {
left: 100%;
position: absolute;
top: 0;
visibility: hidden;
margin-top: -1px;
}
.dropdown-menu li:hover .sub-menu {
visibility: visible;
}
.dropdown:hover .dropdown-menu {
display: block;
}
.nav-tabs .dropdown-menu, .nav-pills .dropdown-menu, .navbar .dropdown-menu {
margin-top: 0;
}
.navbar .sub-menu:before {
border-bottom: 7px solid transparent;
border-left: none;
border-right: 7px solid rgba(0, 0, 0, 0.2);
border-top: 7px solid transparent;
left: -7px;
top: 10px;
}
.navbar .sub-menu:after {
border-top: 6px solid transparent;
border-left: none;
border-right: 6px solid #fff;
border-bottom: 6px solid transparent;
left: 10px;
top: 11px;
left: -6px;
}
Just in case of someone wants a short answer.
HTML
<li class="dropdown">
Dropdown <b class="caret"></b>
<ul class="dropdown-menu">
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
</ul>
</li>
CSS
.dropdown:hover .dropdown-menu {
display: block;
}
You can try it here
In your css put:
.dropdown-menu {display:block;}
.open > .dropdown-menu {display:block !important;}
And your javascript:
$(".dropdown-menu").hide();
I want to make a top navbar with a second level, but not as a dropdown menu. It should apear as a second row under the first one. Example (* means the is the active one):
nav1 | nav2* | nav3
nav2a | nav2b
Should look like this:
<div class="navbar" id="topnavi">
<div class="navbar-inner">
<ul class="nav">
<li>
nav1
<ul class="secondlevel">
<li>nav1a</li>
<li>nav1b</li>
<li>nav1c</li>
</ul>
</li>
<li>
nav2
<ul class="secondlevel">
<li>nav2a</li>
<li>nav2b</li>
</ul>
</li>
<li>
nav3
</li>
</ul>
</div>
</div>
Any ideas?
I used the dropdown class and over-wrote some of the styles so that the nested dropdown items appear as a secondary nav below the primary items. This is the general direction from what I understand- hope it helps!
HTML:
<div class="navbar">
<div class="navbar-inner">
<ul class="nav">
<li class="dropdown">
Dropdown
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
</ul>
</li>
<li class="dropdown">
Dropdown
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
</ul>
</li>
</ul>
</div>
</div>
CSS:
.nav > li {
display: inline-block;
}
.dropdown-menu{
display: inline;
position: relative;
}
.dropdown-menu > li{
display:inline-block;
}