Make bootstrap "dropdown" expand to the side of the button - twitter-bootstrap-3

I'm building a site using the Bootstrap (3.2.0) and I have a button on my page that I'd like to trigger a "dropdown" menu style effect however instead of having the menu expand downward from the button I'd like it to slide out of the right side. The "dropdown" menu items would still be stacked vertically just like normal but instead of having the top of the menu connected to the bottom of the button, the upper-left side of the menu would be connected to the upper-right side of the button.

sounds like a great idea is an example of a side by side nav, i found on the net. http://www.bootply.com/uBVgiR9DDd
.dropdown-menu.multi-column {
width: 400px;
}
.dropdown-menu.multi-column .dropdown-menu {
display: block !important;
position: static !important;
margin: 0 !important;
border: none !important;
box-shadow: none !important;
}
<ul class="nav">
<li class="dropdown"> <a class="" href="#" data-toggle="dropdown">Dropdown Heading</a>
<div class="dropdown-menu multi-column">
<div class="container-fluid">
<div class="row-fluid">
<div class="span6">
<ul class="dropdown-menu">
<li><a class="" href="#">Col 1 - Opt 1</a>
</li>
<li><a class="" href="#">Col 1 - Opt 2</a>
</li>
</ul>
</div>
<div class="span6">
<ul class="dropdown-menu">
<li><a class="" href="#">Col 2 - Opt 1</a>
</li>
<li><a class="" href="#">Col 2 - Opt 2</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</li>
</ul>

Related

Bootstrap 3 - navbar dropdown menu still visible after closing the dropdown - on viewport < 768px

I've been trying to fix the issue with the navbar dropdown menu when using viewport smaller than 768px (mobile/touchscreen).
When tested on touchscreen, one click is supposed to open the dropdown (this works fine), the second click is supposed to close it (closing of the dropdown works, but on touchscreen it still shows the dropdown menu on the side like it is ul.dropdown-menu:hover ).
I am trying to have it hidden after the dropdown toggle is clicked to close, and the cursor is still hovers on the toggle (touchscreen).
Here is the code:
ul.dropdown-menu {
background-color: #4474a8;
}
ul.dropdown-menu li a {
background-color: #4474a8
}
ul.dropdown-menu li a:hover {
background-color: #4474a8;
color: #111111!important;
}
.dropdown:hover .dropdown-menu {
display: block;
}
a.dropdown-toggle:focus {
color: #2f1b09;
}
.dropdown-link {
text-align: center;
background-color: #4474a8;
color: #FFFFFF !important;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<body>
<div class="container-fluid">
<div class="row">
<div class="col-md-1"></div>
<div class="col-md-10">
<img src="#" class="img-responsive center-block" id="logo-top">
</div>
<div class="col-md-1"></div>
</div>
</div>
<nav class="navbar">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="fa fa-anchor"></span>
</button>
</div>
<div class="navbar-collapse collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="active" id="active-nav">Home</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" href="#">MENU 1<span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><i class="fa fa-ship" aria-hidden="true"></i> SUBMENU 1</li>
<li> SUBMENU 2</li>
<li> SUBMENU 3<b>$</b></li>
<li> SUBMENU 4</li>
</ul>
</li>
<li>MENU 2</li>
<li>MENU 3</li>
<li>MENU 4</li>
<li class="dropdown">
<i class="fa fa-camera" aria-hidden="true"></i> MENU 5<span class="caret"></span>
<ul class="dropdown-menu">
<li>Photos</li>
<li>Video</li>
<li><i class="fa fa-youtube" aria-hidden="true"></i>YouTube</li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
<!-- # #banner-->
<div class="container-fluid" id="banner">
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6" id="bannerCol1L">
</div>
<!-- / #bannerCol1L -->
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6" id="bannerCol2R">
<a class="orange pillboxLarge" id="getstarted">BUTTON</a>
</div>
</div>
<!-- / .row -->
</div>
<!-- / .container-fluid #banner -->
</body>
In your CSS, delete the following:
.dropdown:hover .dropdown-menu {
display: block;
}

bootstrap navbar - show only submenu on mobile

I have a standard bootstrap navbar, that collapse on mobile. Here below the code, for your reference:
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">WebSiteName</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Menu with dropdown <span class="caret"></span></a>
<ul class="dropdown-menu">
<li>Submenu voice 1</li>
<li>Submenu voice 2</li>
<li>Submenu voice 3</li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
I would like, after clicking on the hamburger menu on mobile, to get directly the 3 <li> "Submenu voice x" and hide the parent <li> (class="dropdown").
How can I achieve this result? Thank you
You can use CSS for this:
#media (max-width: 767px) {
.navbar-nav .dropdown-menu {
display: block;
position: static;
float: none;
width: auto;
margin-top: 0;
background-color: transparent;
border: 0;
-webkit-box-shadow: none;
box-shadow: none;
}
.dropdown-toggle {
display: none !important;
}
.navbar-inverse .navbar-nav .dropdown-menu > li > a {
color: #9d9d9d;
}
}
CODEPEN
I had to add the below to .navbar-nav .dropdown-menu in order to make it work.
opacity:1;
visibility: visible;
Try below code.
HTML:
<nav class="main-menu navbar-expand-md">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent1" aria-controls="navbarSupportedContent1" aria-expanded="false" aria-label="Toggle navigation">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="navbar-collapse collapse clearfix" id="navbarSupportedContent1">
<ul class="navigation clearfix">
<li class="current dropdown"><a routerLink="/">Home</a>
</li>
<li class="dropdown">About
<ul class="dropdown-menu">
<li>Company Overview</li>
<li>Vision Mission</li>
<li>Ethics & Core Values</li>
</ul>
</li>
</ul>
</div>
</nav>
CSS:
.dropdown:hover > .dropdown-menu{
display: block;
}

Hover on Navbar Social Icons

I can get the hover effect of the icon over just the font awesome, but not over the complete separate elements. And I want each element to have its original color on hover.
how can I get the right hover effect?
Here is the HTML Code used
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right socialnav">
<li class="twitternav"><i class="fa fa-twitter"></i></li>
<li class="facebooknav"><i class="fa fa-facebook"></i></li>
<li class="instagramnav"><i class="fa fa-instagram"></i></li>
<li class="youtubenav"><i class="fa fa-youtube"></i></li>
<li><i class="fa fa-envelope"></i></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="active">Home</li>
<li>About Us</li>
<li>Our Services</li>
<li>BODY SCULPTING</li>
<li>Clinical</li>
<!--<li>Testimonials</li>-->
<li>Gallery</li>
<li>PROMOTIONS</li>
<li>Team</li>
<li>Contact</li>
</ul>
And here is the CSS code that I have tried.
.navbar-right .socialnav > li .facebooknav a:hover {
color: #4060A5 !important;
}
.social .fa-twitter:hover {
color: #00ABE3;
}
.social .fa-instagram:hover {
color:#517fa4;
}
.social .fa-youtube:hover {
color:#C31A1E;
}
The website is http://www.hardyhealth.com/ (top bar social media icons)
Any help would be awesome thank you!!!
Try .twitternav:hover .fa { color: #yourcolor; }. And so on.

Bootstrap Nav with 2 rows of links on desktop

I need to create a responsive nav with 2 rows of links. I would prefer to use bootstrap since it's already being used on the site. Any help to point me in the right direction would be greatly appreciated!
What I need it to look like
Just create something like this:
<nav>
<div class="container">
<div class="row">
<div class="col-md-*">
</div>
</div>
<div class="row">
<div class="col-md-*">
</div>
</div>
</div>
</nav>
Also just take a look at bootstrap's docs. Here is the link to Bootstrap's site
You need to spend some time looking at Bootstrap Navbar section also spend some time hacking around the examples and you will soon get the hang.
If you want a BIG, deep menu have a look at Yamm (yet another mega dropdown menu) or something similar. There are lots out there just search for bootstrap menus or dropdown menus... But the basic nav is very flexible.
After searching around for several hours, I was able to find a few different sources that ended up helping me figure it out.
Here's what my code ended up looking like. It's not perfect yet, but almost there.
Thanks everyone!
#nav-div { /*This is the div that wraps the entire logo and nav content*/
width:100%;
position: fixed;
top:0;
left:0;
z-index: 10;
margin: 0;
padding:0;
}
#nav-wrapper { /*This is the div that sizes the nav down to a col-md-9*/
padding:0;
margin:0;
}
#nav-container{
padding:0px;
}
#nav-top-row {
background-color: #6D6E70;
color: #fff;
padding: 0px 10px;
}
#nav-top-row a {
color:#fff;
padding-top:5px;
padding-bottom:5px;
font-size: 12px;
}
#nav-top-row a:hover {
background-color: #CCCCCC;
}
#nav-bottom-row {
background-color: #009578;
padding:0px 10px;
}
#nav-bottom-row a {
color:#fff;
}
#nav-bottom-row .dropdown-menu li {
background-color:#00806B;
}
#nav-bottom-row .dropdown-menu li a:hover {
background-color:#009578;
}
#nav-bottom-row li.dropdown.open a.dropdown-toggle {
background-color:#00806B;
}
#logo {
margin-top:35px;
width:90%;
max-width:250px;
margin-right:auto;
margin-left:auto;
}
#logo-div {
padding:0px;
background:rgba(255,255,255,.8);
}
.push-down { /*invisible div with no content that pushes down the main body content*/
margin-top:75px;
}
<div id="nav-div"class="">
<div id="logo-div" class="col-md-3">
<a href="#">
<img src="HM-Logo_Grn.png" id="logo" class="img img-responsive">
</a>
</div>
<div id="nav-wrapper" class="col-md-9">
<!-- Fixed navbar -->
<nav id="full-nav" class="navbar navbar-default">
<div id="nav-container" class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<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="#">Project name</a> -->
</div>
<div id="navbar" class="navbar-collapse collapse">
<div id="nav-top-row" class="row">
<ul class="nav navbar-nav navbar-right ">
<li>SERVICES</li>
<li>ACCESS REPORT</li>
<li>REQUEST INSPECTION</li>
</ul>
</div>
<div id="nav-bottom-row" class="row">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
COMPANY <span class="caret"></span>
<ul class="dropdown-menu">
<li>PRESS RELEASES</li>
<li>NEWSROOM</li>
<li>AWARDS</li>
<li>MEDIA ASSETS</li>
</ul>
</li>
<li>RESOURCES</li>
<li>BUYERS</li>
<li>SELLERS</li>
<li>AGENTS</li>
</ul>
</div>
</div><!--/.nav-collapse -->
</div>
</nav>
</div>
</div>
<div class="push-down"></div>

Bootstrap 3 - Fixed Responsive Navbar in container (without background color at the sides)

How to?
Fixed navbar at center, but without background color at the sides.
The width of the navbar should be as that of the container and then the background color of the navbar to the sides of the container (which contains it) you should not see.
Any idea?
Furthermore the navbar must downsize at the resize of the width of the container, and then of the page: so rensponsive navbar!
How to?
Thanks in advance.
Fix the default navbar from: http://getbootstrap.com/examples/navbar/
wrap the navbar in its own .container div and wrap this div in an other div you fix:
#fixme {position: fixed;left: 0;right: 0; top:0;}
/* prevent overlap */
body{padding-top:70px;}
html
<div id="fixme">
<div class="container">
<!-- your navbar here -->
</div>
</div>
Other example One way to do this (there will be many others). Take static navbar example from: http://getbootstrap.com/examples/navbar-fixed-top/
The navbar code already contains a div with class container which wraps the navbar content and set the width for the different grids (so content is responsive) already.
The 100% width "effect" is set by a background color (and border) of the .navbar-default class (set 100% width by the .navbar-fixed-top left: and right both 0).
Remove this background and border:
.navbar-default {
background-color:transparent;
border: none;
}
After this the navbar it self do not have a background color. To solve wrap your nav bar inside a extra div (inside the .containter div) and apply a background color on it:
.navbar > .container > div
{
background-color: pink;
}
When you apply this background on the .container without the extra div your background will 15px wider then your content on both sides due to the gutter of the grids (padding).
Example: http://bootply.com/79742
html:
<div class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div>
<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="navbar-collapse 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>
<ul class="nav navbar-nav navbar-right">
<li>Default</li>
<li>Static top</li>
<li class="active">Fixed top</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
Im using the last version of Bootsrap and i had to override the "navbar-default" class like this :
.navbar-default{
background-image: none;
-webkit-box-shadow: none;
border-style : none;
background-color: white; // the color i chose
}
The result is my navbar has no more border/background style, and i can finally apply mine in my div ! (phewww)
I was struggling with the same issue. I solved it by adding some jquery that makes the ".navbar" the same width as the ".container".
$(document).ready(function () {
var siteWidth = $('.container').width();
$('.navbar').width(siteWidth);
});