bootstrap multilevel dropdown - html

Here's the jsfiddle to the dropdown menu. If you click on any link it will actually take you to the main page that I am working on. If you try clicking on the sub-menu under human practices nothing comes up.
Please help, I don't understand why the sub-menu is not being generated. Thanks so much.
Here is the fiddle:http://jsfiddle.net/maxgitt/a9vq8v9p/
Here is a direct link to the problem of creating a submenu within Human Practices: http://2015.igem.org/Template:Michigan

This might help you or give you some ideas, the JS is so your submenu will open and remain open after Click.
You don't have to keep the open submenu directly underneath it's parent but you'll find the submenu going off the page once the viewport is reduced if you aren't careful where you position it. The CSS rules that are commented out in .dropdown-submenu > .dropdown-menu will help to re-position the submenu if you want to.
(function($) {
$(document).ready(function() {
$('ul.dropdown-menu [data-toggle=dropdown]').on('click', function(event) {
event.preventDefault();
event.stopPropagation();
$(this).parent().siblings().removeClass('open');
$(this).parent().toggleClass('open');
});
});
})(jQuery);
.dropdown-submenu {
position: relative;
}
.dropdown-submenu > .dropdown-menu {
/*top: 0;
left: 15%;*/
margin-top: 5px;
margin-left: -1px;
}
.navbar .dropdown-submenu,
.navbar .dropdown-menu {
border-radius: 0;
box-shadow: none;
}
<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" />
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-1"> <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</a>
</div>
<div class="collapse navbar-collapse" id="navbar-1">
<ul class="nav navbar-nav">
<li>Home <span class="sr-only">(current)</span>
</li>
<li class="dropdown"> Project <span class="caret"></span>
<ul class="dropdown-menu">
<li>Design
</li>
<li>Experiments & Protocols
</li>
<li>Results & Discussion
</li>
<li>Collaborations
</li>
<li>Parts
</li>
</ul>
</li>
<li>Notebook
</li>
<li>Modeling
</li>
<li class="dropdown">Human Practices<b class="caret"></b>
<ul class="dropdown-menu">
<li>Background
</li>
<li>Diseases and Applications
</li>
<li>Current Detection Methods
</li>
<li class="dropdown dropdown-submenu">Informed Design <span class="caret"></span>
<ul class="dropdown-menu">
<li>Survey
</li>
<li>Biotech/Pharmaceutical Industry
</li>
<li>Food Science Industry
</li>
<li>Medical Practice: Point of Care Testing
</li>
</ul>
</li>
</ul>
</li>
<li>Safety
</li>
</ul>
</div>
</nav>

Related

Bootstrap multi level menu issues on mobile

My problem is, that when i am looking at the site on mobile, i cant see the submenus.
For example:
I click down the "Alaplap" menu, then it displays the submenu, "Intel alaplap" and "amd alaplap". But the "Intel alaplap" also has a submenu, and i cant see that on mobile.
<ul class="nav nav-justified">
<li>Alaplap<b class="caret"></b>
<ul class="dropdown-menu">
<li class="dropdown-submenu">Intel alaplap
<ul class="dropdown-menu">
<li class="dropdown-submenu">Asus alaplap
<ul class="dropdown-menu">
<li>Asus Z370 alaplap</li>
<li class="dropdown-submenu">Asus Z390 Express alaplap
<ul class="dropdown-menu">
<li>aaaaa</li>
<li>bbbb</li>
</ul>
</li>
</ul>
</li>
<li>MSI alaplap</li>
<li>Gigabyte alaplap</li>
</ul>
</li>
<li>AMD alaplap</li>
</ul>
</li>
<li>SSD meghajtó</li>
<li>Videókártya</li>
<li>Memória</li>
<li>Tápegység</li>
<li>Merevlemez</li>
<li>Monitor</li>
<li>Telefontok<b class="caret"></b>
<ul class="dropdown-menu">
<li>Samsung telefontok</li>
</ul>
</li>
</ul>
You can take a look at my demo site at here: My demo site
This is happening because your site is still showing them in horizontal orientation when switching to responsive view which is always going to lead to a bad UX on mobile. This is how I would approach it myself. Feel fre to thank Ricard Torres if this was helpful.
.dropdown-submenu {
position: relative;
}
.dropdown-submenu > .dropdown-menu {
top: 0;
left: 100%;
margin-top: -6px;
margin-left: -1px;
}
.dropdown-submenu:hover > .dropdown-menu {
display: block;
}
.dropdown-submenu:hover > a:after {
border-left-color: #fff;
}
.dropdown-submenu.pull-left {
float: none;
}
.dropdown-submenu.pull-left > .dropdown-menu {
left: -100%;
margin-left: 10px;
}
and here is the actual html to power your menu...feel free to change the css accordingly.
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active">Link <span class="sr-only">(current)</span></li>
<li>Link</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Link</li>
<li class="dropdown-submenu">
<a tabindex="-1" href="#">Second Level Menu ! <i class="fa fa-chevron-right"></i></a>
<ul class="dropdown-menu">
<li><a tabindex="-1" href="#">Link 1</a></li>
<li>Lik 2</li>
<li>Link 3</li>
</ul>
</li>
<li>Link</li>
<li>Link</li>
</ul>
</li> <!-- .dropdown -->
</ul> <!-- .nav .navbar-nav -->
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
Codepen solution to see it working

Keep background from changing color on .dropdown-toggle component

I've got this bit of code here: (Update: I put the entire navbar code here now because I realized with the limited amount originally posted may be limiting the ability to figure out the problem)
<nav class="navbar navbar-inverse navsize">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#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>
<a class="navbar-brand" ><img id="logo" src="/Images/SC2_MyLink_Logo.png" alt="SC2 Logo"/></a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul id="navposition" class="nav navbar-nav">
<li class="individualbtnposition col-lg-2">#Html.ActionLink("Home", "Index", "Home")</li>
<li class="dropdown individualbtnposition">
Our Company<span class="caret"></span>
<ul class="dropdown-menu">
<li>#Html.ActionLink("Our History", "Index", "OurCompany")</li>
<li>#Html.ActionLink("Facilities", "Facilities", "OurCompany")</li>
</ul>
</li>
<li class="dropdown individualbtnposition">
Employee Services<span class="caret"></span>
<ul class="dropdown-menu">
<li class="dropdown dropdown-submenu">
Forms
<ul class="dropdown-menu">
<li>#Html.ActionLink("HR Forms", "HRForms", "FormsHandlers")</li>
<li>#Html.ActionLink("Corporate Forms", "CorporateForms", "FormsHandlers")</li>
<li>#Html.ActionLink("Employee Benefits", "EmployeeBenefitsForms", "FormsHandlers")</li>
<li>#Html.ActionLink("Accident Forms", "AccidentForms", "FormsHandlers")</li>
<li>#Html.ActionLink("Payroll Forms", "PayrollForms", "FormsHandlers")</li>
</ul>
</li>
<li>Pay Stubs</li>
<li>#Html.ActionLink("FAQ", "FAQ", "FormsHandlers")</li>
</ul>
</li>
<li class="dropdown individualbtnposition">
Support Services<span class="caret"></span>
<ul class="dropdown-menu">
<li>IT Support</li>
<li>#Html.ActionLink("Purchasing Ticket", "OnlineForms", "FormsHandlers", new {id = "purchasing-services-form" })</li>
<li>Maint. Support</li>
</ul>
</li>
</ul>
</div>
</div>
<div class="logout col-lg-1">
<a asp-area="" asp-controller="Home" asp-action="Logout">Sign Out</a>
</div>
On the class="dropdown-toggle", when a menu button is clicked, it changes the square around it to black. I don't want it to change color, but I can't seem to figure out how to keep it from doing it. The only thing I could figure out was if I put this code in:
.dropdown-toggle{ background: white; }
Then it changes the background white before clicking it. So I can effect the color before clicking, but after clicking I can't seem to get it to just not be changed at all. Any ideas? Here is a picture of what it is doing for a reference:
I was able to use the dev tools to narrow it down to exactly what was putting the black there, then I just manually changed it. here is the piece of css that I put in to fix it:
.navbar-inverse .navbar-nav > .open > a, .navbar-inverse .navbar-nav > .open > a:hover, .navbar-inverse .navbar-nav > .open > a:focus {
color: #fff;
background-color: initial;
}

bootstrap nav bar nested <ul> not showing properly under parent

When you view the page as mobile the main navigation bar does not show the drop downs properly underneath their respected parent link. I have search and cannot seem to find a solution. Currently the dropdown menus show under and to the left of the main link. You can see a live demonstration at http://beta.lofbc.org
<nav class="navbar navbar-default">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand hidden-lg hidden-md hidden-sm" href="#">Life of Faith Bible Church</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="navbar-collapse-1">
<ul class="nav nav-justified">
<li>#Html.ActionLink("HOME", "index", "Home")</li>
<li role="presentation" class="dropdown">
ABOUT US <span class="caret"></span>
<ul class="dropdown-menu">
<li>#Html.ActionLink("Church Services", "ChurchServices", "About")</li>
<li>#Html.ActionLink("What to Expect", "WhatToExpect", "About")</li>
<li>#Html.ActionLink("What we Believe", "whatwebelieve", "About")</li>
<li>#Html.ActionLink("Leadership", "Leadership", "About")</li>
</ul>
</li>
<li role="presentation" class="dropdown">
MINISTRIES <span class="caret"></span>
<ul class="dropdown-menu">
<li>#Html.ActionLink("Children", "Children", "Ministries")</li>
<li>FAA</li>
<li>God's Girlz Club</li>
<li>AfterShock Youth</li>
<li>Young Adults</li>
<li>Men of Impact</li>
<li>Women</li>
<li>God's Golden Girls</li>
<li>The Great Giveaway</li>
</ul>
</li>
<li>#Html.ActionLink("EVENTS", "", "Events")</li>
<li role="presentation" class="dropdown">
MEDIA <span class="caret"></span>
<ul class="dropdown-menu">
<li>Live Stream</li>
<li>#Html.ActionLink("Service Archives", "ServiceArchives", "Media")</li>
<li>TV Broadcast</li>
<li>Photo Album</li>
</ul>
</li>
<li>STORE</li>
<li role="presentation" class="dropdown">
CONTACT <span class="caret"></span>
<ul class="dropdown-menu">
<li>#Html.ActionLink("Send us a Message", "index", "contactus") </li>
<li>Submit Testimony</li>
<li>Prayer Request</li>
<li>#Html.ActionLink("Give", "Donate", "Giving")</li>
</ul>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
This is happening because your nested <ul> tags are absolutely positioned. An absolutely positioned element cannot move relatively positioned elements so even if you moved it across it will simply appear on top of your existing buttons.
My fix would be to apply the following css to the nested <ul> tags:
#media (max-width: 767px) {
.nav-justified>.dropdown .dropdown-menu {
position: relative;
width: 100%;
background-color: #1c5168;
}
.nav-justified>.dropdown .dropdown-menu li {
color: lightblue;
text-align: center;
}
}
Placing it inside a media query will stop the css from applying to your menu on desktop layouts.
You will still have to add more styling to get the menu to look nice but this will fix your positioning issue.
Just for reference here is a good article about the position property with examples of how it works: https://css-tricks.com/almanac/properties/p/position/

bootstrap navbar dropdown menu background not working

To simplify this as much as possible, i am basically adding a bootstrap navbar to a page, one of the tabs has a dropdown menu which has a choice of 5 sub options. I have found that the background is only showing to the bottom of the first sub option. The CSS sets the height to 100% which is what i would like, if i change the CSS to say 500px; it will expand the area.
<nav class="navbar navbar-default">
<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>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li><a class="active" href="index.html">Home</a></li>
<li><a class="li" href="whatido.html">What I Do</a></li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Travels<span class="caret"></span></a>
<ul class="dropdown-menu">
<li>Asia</li>
<li>Europe</li>
<li>Scotland</li>
<li>Other</li>
<li>And Another</li>
</ul>
</li>
<li><a class="li" href="upcomingtrips.html">Upcoming Trips</a></li>
<li><a class="li"href="aboutme.html">About Me</a></li>
<li><a class="li" href="gallery.html">Gallery</a></li>
<li><a class="li" href="contactpage.html">Contact</a></li>
</ul>
</div>
</div></nav>
</nav>
the css for the dropdown is simple
.dropdown-menu {
height:100%;
}
the result :
adjustable size
however if i change the css to
.dropdown-menu {
height:300px;
}
i get this result
fixed size
Im struggling to understand why the 100% option doesn't cover the entire area when each sub option is included in the 'dropdown-menu' ul class?
In bootstrap for .dropdown-menu class position: absolute; is there. So height in percentage wont work. If remove the position: absolute; from dropdown class the percentage of height is working.

In Bootstrap, how do I place links that are outside of the Navbar, inside the mobile Navbar only? (without having to write them twice in the HTML)

I'm using Bootstrap.
I have links that are outside of the Navbar.
</nav>
<ul>
<li>Outside Link</li>
<li>Outside Link</li>
<li>Outside Link</li>
<li>Outside Link</li>
<ul>
I also have the same links inside the Navbar, but with a "visible-xs" class attached, so that they only appear inside the Mobile Navbar. (with hamburger toggle icon menu)
<ul class="visible-xs">
<li>Outside Link</li>
<li>Outside Link</li>
<li>Outside Link</li>
<li>Outside Link</li>
<ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
My current code works the way I would like, however, I do not want to write out the HTML links twice.
http://codepen.io/Goatsy/pen/yJeqjz
How do I place the outside links, inside ONLY the Mobile Navbar, without having to write the links twice in the HTML?
Ultimately, I would like these "outside links" to show on Desktop, outside of the navbar.
For Mobile, they will be, essentially, "moved" inside the navbar.
You can do this with CSS and the right HTML structure. Seperate your outside links from your standard links using navbar-right, then use position: absolute inside a media query so they are only out of the navbar above 767px.
#media (min-width: 767px) {
.navbar.navbar-default .ul-outside {
position: absolute;
top: 100%;
left: 0;
}
}
Working Example I
/*FOR DEMO ONLY*/
.navbar.navbar-default {
margin-bottom: 0;
}
/*FOR DEMO ONLY*/
#media (min-width: 767px) {
.navbar.navbar-default .ul-outside {
position: absolute;
top: 100%;
left: 0;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.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" />
<nav class="navbar navbar-default navbar-static-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Brand</a>
</div>
<div class="collapse navbar-collapse" id="navbar">
<ul class="nav navbar-nav navbar-left">
<li class="active">Link <span class="sr-only">(current)</span>
</li>
<li>Link
</li>
<li>Link
</li>
<li>Link
</li>
</ul>
<ul class="nav navbar-nav navbar-right ul-outside">
<li>Outside
</li>
<li>Outside
</li>
<li>Outside
</li>
<li>Outside
</li>
</ul>
</div>
</div>
</nav>
<!--DEMO CONTENT-->
<div class="jumbotron">
<div class="container">
<h1>
Outer Links
</h1>
</div>
</div>
<!--DEMO CONTENT-->
Working Example II:
/*FOR DEMO ONLY*/
.navbar.navbar-default {
margin-bottom: 0;
}
/*FOR DEMO ONLY*/
#media (min-width: 767px) {
.navbar.navbar-default .ul-outside {
position: absolute;
width: 100%;
top: 100%;
left: 0;
}
.navbar.navbar-default .ul-outside > li {
float: none;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<nav class="navbar navbar-default navbar-static-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Brand</a>
</div>
<div class="collapse navbar-collapse" id="navbar">
<ul class="nav navbar-nav navbar-left">
<li class="active">Link <span class="sr-only">(current)</span>
</li>
<li>Link
</li>
<li>Link
</li>
<li>Link
</li>
</ul>
<ul class="nav navbar-nav navbar-right ul-outside">
<li>Outside
</li>
<li>Outside
</li>
<li>Outside
</li>
<li>Outside
</li>
</ul>
</div>
</div>
</nav>
<!--DEMO CONTENT-->
<div class="jumbotron">
<div class="container">
<h1>
Outer Links
</h1>
</div>
</div>
<!--DEMO CONTENT-->