I'm adjusting someone else's code, html is not my thing. For some reason the code makes the drop down menu change, sometimes to two parts. I would much rather a dropdown menu that just works directly and doesn't change. Was hoping someone can tell me why it acts the way it does.
Below is the code and am including a before and after image
Thanks
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href=""></a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href=“/index.html” id="dropdown01" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Menu</a>
<div class="dropdown-menu" aria-labelledby="dropdown01">
<a class="dropdown-item" href="index.html">Home</a>
<a class="dropdown-item" href="sales.html">Sales</a>
<a class="dropdown-item" href="/management">Management</a>
<a class="dropdown-item" href="/bartending">Bartending</a>
<a class="dropdown-item" href="/print">My Name In Print</a>
<a class="dropdown-item" href="/guerillamarketing">Guerilla Marketing</a>
</div>
</li>
</ul>
</div>
usually (but not always) a dropdown list is a nested list inside of an li that is controlled by a button like this
<ul>
<li>regular link</li>
<li>
<button>drop down</button>
<ul>
<li>drop down link 1</li>
<li>drop down link 2</li>
</ul>
</li>
</ul>
so yours might end up looking something like this:
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href=""></a>
</li>
<li class="nav-item dropdown">
<button>menu</button>
<ul>
<li><a class="dropdown-item" href="index.html">Home</a></li>
<li><a class="dropdown-item" href="sales.html">Sales</a></li>
<li><a class="dropdown-item" href="/management">Management</a></li>
<li><a class="dropdown-item" href="/bartending">Bartending</a></li>
<li><a class="dropdown-item" href="/print">My Name In Print</a></li>
<li><a class="dropdown-item" href="/guerillamarketing">Guerilla Marketing</a</li>
</ul>
</li>
</ul>
</div>
Ill also include an example of a drop down I created to help you with those aria attributes sorry in advance for the lack of style on it. Hope this helps.
<header id="sitewide-header">
<ul id="visible-navigation">
<li id="logo-container">vertical template</li>
<li id="control-container"><button id="menu-button" aria-expanded="false" aria-controls="toggled-navigation">menu</button></li>
</ul>
<nav id="navigation-container">
<ul id="toggled-navigation" aria-hidden="true" aria-labelledby="menu-button">
<li>home section</li>
<li>section two</li>
<li>
<button id="dropdown1-button" aria-expanded="false" aria-controls="dropdown-one">three – five</button>
<ul id="dropdown-one" aria-hidden="true" aria-labelledby="dropdown1-button">
<li>section three</li>
<li>section four</li>
<li>section five</li>
</ul>
</li>
<li>section six</li>
</ul>
</nav>
</header>
Related
I am trying to make a Bootstrap navbar that will display the items that can be seen in the code. All of my other links work and take me to their respected pages, but whenever I hit the dropdown in the navbar nothing happens. It is the dropdown portion that I can not get to work and I am not sure what else I need to add. Any help will be greatly appreciated.
This is Bootstrap5
<nav class="navbar navbar-expand-lg navbar-dark" style="background-color: #4f2fb6;">
<a class="navbar-brand" href="#">GCU</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#collapsibleNavbar" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation"></button>
</button>
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="index.html">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="tando.html">Course Matrix</a>
</li>
<li class="nav-item">
<a class="nav-link" href="media.html">Media</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Topics
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<li><a class="dropdown-item" href="#topic1" data-bs-toggle="collapse">Topic 1</a></li>
<li><a class="dropdown-item" href="#topic2" data-bs-toggle="collapse">Topic 2</a></li>
<li><a class="dropdown-item" href="#topic3" data-bs-toggle="collapse">Topic 3</a></li>
<li><a class="dropdown-item" href="#topic4" data-bs-toggle="collapse">Topic 4</a></li>
<li><a class="dropdown-item" href="#topic5" data-bs-toggle="collapse">Topic 5</a></li>
<li><a class="dropdown-item" href="#topic6" data-bs-toggle="collapse">Topic 6</a></li>
<li><a class="dropdown-item" href="#topic7" data-bs-toggle="collapse">Topic 7</a></li>
</ul>
</li>
</ul>
</div>
</nav>
I am building a site here:
Website Link
The drop-down navbar menu is working fine except the fact that when there is a mouse-over on the items to the right of the navbar, the first drop-down menu activates. (i.e. Click on Administration and both its drop-down menu and the drop-down menu under "who are we" also drops down!)
Any further suggestions, please?
The code is as follows:
<nav id="myNav" class="navbar navbar-inverse navbar-top" role="navigation">
<div class="container dropdown">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header dropdown">
-->
Toggle navigation
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse dropdown" id="bs-example-navbar-collapse-1" data-hover="dropdown">
<ul class="nav navbar-nav navbar-right dropdown">
<li>
_Home
</li>
<li class="dropdown">
_Who are we?<b class="caret"></b>
<ul class="dropdown-menu">
<li class="dt_bg dropdown">
_About the Association
</li>
<li class="">
_Objectives
</li>
<li class="dt_bg">
_Quem Somos?
</li>
</ul>
</li>
<li class="dropdown">
_How do we help?<b class="caret"></b>
<ul class="dropdown-menu">
<li class="dt_bg dropdown">
_Snips
</li>
<li>
_Other
</li>
<li class="dt_bg">
_Forms
</li>
</ul>
</li>
<li class="dropdown">
_How can <strong>You</strong> help?<b class="caret"></b>
<ul class="dropdown-menu">
<li class="dt_bg dropdown">
_Our Shops
<ul class="dropdown-menu sub-menu">
<li class="dt_bg dropdown">
_Alvor
</li>
<li>
_Albufeira
</li>
<li class="dt_bg">
_Silves
</li>
</ul>
</li>
<li>
_Fundraising
</li>
<li class="dt_bg">
_Membership
</li>
</ul>
</li>
<li class="dropdown">
_Latest News<b class="caret"></b>
<ul class="dropdown-menu">
<li class="dt_bg dropdown">
_Upcoming Events
</li>
<li>
_Other
</li>
</ul>
</li>
<li class="dropdown">
_Administration<b class="caret"></b>
<ul class="dropdown-menu">
<li class="dt_bg dropdown">
_Structure of the association
<ul class="dropdown-menu sub-menu">
<li class="dt_bg dropdown">
_Management Board
</li>
<li>
_Fiscal Council
</li>
<li class="dt_bg">
_Annual General Assembly
</li>
</ul>
</li>
<li>
_Reports & Accounts
</li>
</ul>
</li>
<li>
_Vet Clinics
</li>
<li>
_Contact
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
Any help in seeing where the problem is would be gratefully received as my eyes are going after hours of tring nto find the problem.
Many Thanks
Update:
I have applied the solution proposed by #Spade but the situation remains.
Using [link]http://apaaportugal.doidosou.eu/useful_links.php as a test page (no carousel) onmouseover on any dropdown menu item also activates the first drop-down under item "_who are we".
Javascript code on the page is:
<!-- jQuery -->
<script src="js/jquery.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script>
<!-- Sub-Menu JavaScript -->
<script src="js/sub_menu.js"></script>
<!-- header script -->
<script>
var headerHeight = 200;
$(window).bind('scroll', function () {
if ($(window).scrollTop() > headerHeight) {
$('#myNav').removeClass('navbar-top');
$('#myNav').addClass('navbar-fixed-top');
} else {
$('#myNav').removeClass('navbar-fixed-top');
$('#myNav').addClass('navbar-top');
}
});
</script>
<!-- Bootstrap Dropdown Hover JS -->
<script src="js/bootstrap-dropdownhover.min.js"></script>
<script>
$(function() {
$('.navbar .dropdown').hover(function() {
$(this).find('.dropdown-menu').first().stop(true, true).delay(250).slideDown();
}, function() {
$(this).find('.dropdown-menu').first().stop(true, true).delay(100).slideUp();
});
$(window).resize(function() {
var width = $(this).width();
if (width < 769) {
$('.navbar .dropdown').removeClass('test');
} else {
$('.navbar .dropdown').addClass('test');
}
});
});
</script>
Navbar Html code as follows:
<!-- Header Content -->
<div class="container">
<div class="row">
<div class="col-lg-1">
<img src="/images/APPA_logo_R_80.png"><a class="navbar-brand" href="#"></a>
</div>
<div class="col-lg-11">
<div>
<h1 class="h_header">APAA - Association for the Protection of Animals in the Algarve</h1>
<h3 class="h_header">Associação de Protecção Animal do Algarve</h3>
</div>
</div>
</div>
</div>
<!-- /.container -->
<!-- Navigation -->
<nav id="myNav" class="navbar navbar-inverse navbar-top" role="navigation">
<div class="container dropdown">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header dropdown">
<!-- <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" data-hover="dropdown">-->
<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>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse dropdown" id="bs-example-navbar-collapse-1" data-hover="dropdown">
<ul class="nav navbar-nav navbar-right dropdown">
<li>
_Home
</li>
<li class="dropdown">
_Who are we?<b class="caret"></b>
<ul class="dropdown-menu">
<li class="dt_bg dropdown">
_About the Association
</li>
<li class="">
_Objectives
</li>
<li class="dt_bg">
_Quem Somos?
</li>
</ul>
</li>
<li class="dropdown">
_How do we help?<b class="caret"></b>
<ul class="dropdown-menu">
<li class="dt_bg dropdown">
_Snips
</li>
<li>
_Other
</li>
<li class="dt_bg">
_Forms
</li>
</ul>
</li>
<li class="dropdown">
_How can <strong>You</strong> help?<b class="caret"></b>
<ul class="dropdown-menu">
<li class="dt_bg dropdown">
_Our Shops
<ul class="dropdown-menu sub-menu">
<li class="dt_bg dropdown">
_Alvor
</li>
<li>
_Albufeira
</li>
<li class="dt_bg">
_Silves
</li>
</ul>
</li>
<li>
_Fundraising
</li>
<li class="dt_bg">
_Membership
</li>
</ul>
</li>
<li class="dropdown">
_Latest News<b class="caret"></b>
<ul class="dropdown-menu">
<li class="dt_bg dropdown">
_Upcoming Events
</li>
<li>
_Other
</li>
</ul>
</li>
<li class="dropdown">
_Administration<b class="caret"></b>
<ul class="dropdown-menu">
<li class="dt_bg dropdown">
_Structure of the association
<ul class="dropdown-menu sub-menu">
<li class="dt_bg dropdown">
_Management Board
</li>
<li>
_Fiscal Council
</li>
<li class="dt_bg">
_Annual General Assembly
</li>
</ul>
</li>
<li>
_Reports & Accounts
</li>
</ul>
</li>
<li class="dropdown">
_Useful Links<b class="caret"></b>
<ul class="dropdown-menu">
<li class="dt_bg dropdown">
_Algarve - Veterinary Surgeries
</li>
<li>
_Algarve - Other animal-related institutions
</li>
</ul>
</li>
<li>
_Contact
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
Two things need to be changed:
1) Replace "Script to Activate the Carousel" with the following:
$(function() {
$('.navbar .dropdown').hover(function() {
$(this).find('.dropdown-menu').first().stop(true, true).delay(250).slideDown();
}, function() {
$(this).find('.dropdown-menu').first().stop(true, true).delay(100).slideUp();
});
$(window).resize(function() {
var width = $(this).width();
if (width < 769) {
$('.navbar .dropdown').removeClass('test');
} else {
$('.navbar .dropdown').addClass('test');
}
});
});
2) Replace the code you shared for Navigation with the following:
<!-- Navigation -->
<nav id="myNav" class="navbar navbar-inverse navbar-top" role="navigation">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<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>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse " id="bs-example-navbar-collapse-1" data-toggle="dropdown">
<ul class="nav navbar-nav">
<li>
_Home
</li>
<li class="dropdown">
_Who are we?<b class="caret"></b>
<ul class="dropdown-menu">
<li class="dt_bg dropdown">
_About the Association
</li>
<li class="">
_Objectives
</li>
<li class="dt_bg">
_Quem Somos?
</li>
</ul>
</li>
<li class="dropdown">
_How do we help?<b class="caret"></b>
<ul class="dropdown-menu">
<li class="dt_bg dropdown">
_Snips
</li>
<li>
_Other
</li>
<li class="dt_bg">
_Forms
</li>
</ul>
</li>
<li class="dropdown">
_How can <strong>You</strong> help?<b class="caret"></b>
<ul class="dropdown-menu">
<li class="dt_bg dropdown">
_Our Shops
<ul class="dropdown-menu sub-menu">
<li class="dt_bg dropdown">
_Alvor
</li>
<li>
_Albufeira
</li>
<li class="dt_bg">
_Silves
</li>
</ul>
</li>
<li>
_Fundraising
</li>
<li class="dt_bg">
_Membership
</li>
</ul>
</li>
<li class="dropdown">
_Latest News<b class="caret"></b>
<ul class="dropdown-menu">
<li class="dt_bg dropdown">
_Upcoming Events
</li>
<li>
_Other
</li>
</ul>
</li>
<li class="dropdown">
_Administration<b class="caret"></b>
<ul class="dropdown-menu">
<li class="dt_bg dropdown">
_Structure of the association
<ul class="dropdown-menu sub-menu">
<li class="dt_bg dropdown">
_Management Board
</li>
<li>
_Fiscal Council
</li>
<li class="dt_bg">
_Annual General Assembly
</li>
</ul>
</li>
<li>
_Reports & Accounts
</li>
</ul>
</li>
<li class="dropdown">
_Useful Links<b class="caret"></b>
<ul class="dropdown-menu">
<li class="dt_bg dropdown">
_Algarve - Veterinary Surgeries
</li>
<li>
_Algarve - Other animal-related institutions
</li>
</ul>
</li>
<li>
_Contact
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
Also Attaching the result at my side:
I have my dropdown menu in my _Layout.cshtml and clicking on one of the menu items works fine the first time, for example takes me to http://localhost:52098/Home/ViewTable/Scottish Premiership.
If I click on the URL again, it tries taking me to http://localhost:52098/Home/ViewTable/Home/ViewTable/Scottish Premiership
The navigation Code:
div class="navbar navbar-inverse navbar-fixed-top">
<ul class="nav nav-pills">
<li role="presentation" class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
Scotland <span class="caret"></span></a>
<ul class="dropdown-menu multi-level" role="menu">
<li role="presentation"><a role="menuitem" tabindex="-1" href="Home/ViewTable/Scottish Premiership">
Scottish Premiership
</a></li>
<li role="presentation">
<a role="menuitem" tabindex="-1" href="Home/ViewMain/Scottish Championship">
Scottish Championship
</a>
</li>
<li role="presentation">
<a role="menuitem" tabindex="-1">
Scottish First Division
</a>
</li>
<li role="presentation">
<a role="menuitem" tabindex="-1">
Scottish Second Division
</a>
</li>
</ul>
</li>
<li role="presentation" class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-expanded="false">
England <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li role="presentation">
<a role="menuitem" tabindex="-1" href="Home/ViewMain/Scottish Championship">
English Premier League
</a>
</li>
<li role="presentation">
<a role="menuitem" tabindex="-1" href="Home/ViewMain/Scottish Championship">
English Championship
</a>
</li>
</ul>
</li>
</ul>
// #*#Html.MvcSiteMap().Menu(false, true, true, true, true)
#Html.MvcSiteMap().SiteMapPath()*#
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav"></ul>
</div>
</div>
Looks like it's taking a relative path from the one i'm already on + the href on the link, where as what I really want is an absolute path?
Add '/' to the start of your URLs
like /Home/ViewMain/Scottish ChampionShip
And it is always better to use
#Url.Action("MethodName", "Controller")
e.g.
Test
To pass a Parameter in URL
Test
I have a Bootstrap 3 Navbar that has two right-justified <ul> sections which gives me this:
When the menu is collapse for mobile, I get this:
I have two questions related to the collapsed menu. 1) How can I get the buttons to appear at the bottom of the collapsed menu instead of the top? 2) How can I change the styling of the buttons in the collapsed menu (without affecting the style in the horizontal menu)?
Below is the markup for this Navbar. And yes I have a reason for having two separate <ul> sections:
<div class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button class="navbar-toggle" data-toggle="collapse" data-target=".navHeaderCollapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
My Site
</div>
<div class="collapse navbar-collapse navHeaderCollapse">
<ul class="nav navbar-nav navbar-right">
<li>Button One</li>
<li>Button Two</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Item1</li>
<li>Item2</li>
<li>Item3</li>
<li>Item4</li>
</ul>
</div>
</div>
</div>
I ended up finding a simpler solution for the reformatting and reordering of the button links on the collapsed navbar, one that doesn't require new javascript code:
<div class="collapse navbar-collapse navHeaderCollapse">
<ul class="nav navbar-nav navbar-right hidden-xs">
<li>Button One</li>
<li>Button Two</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Item1</li>
<li>Item2</li>
<li>Item3</li>
<li>Item4</li>
</ul>
<ul class="nav navbar-nav visible-xs">
<li><a href="#" >Button One</a></li>
<li><a href="#" >Button Two</a></li>
</ul>
</div>
I simply duplicated the Button One and Button Two <ul> section and added it to the bottom. I then removed the classes and ID on the <a> links so that no button formatting would occur. Finally, I added the hidden-xs bootstrap class to the top <ul> and visible-xs to the bottom <ul> class. That did the trick:
I ran into a similar issue but have been using Bootstrap 4.4 and this can be solved with a simple d-none d-block solution.
<ul class="nav justify-content-center">
<li class="nav-item d-sm-none d-md-block">
<a class="nav-link" href="#">Item 1</a>
</li>
<li class="nav-item d-sm-none d-md-block">
<a class="nav-link" href="#">Item 2</a>
</li>
<li>
<li class="nav-item">
<a class="nav-link" href="#">Item 3</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Item 4</a>
</li>
<li class="nav-item d-none d-sm-block d-md-none">
<a class="nav-link" href="#">Item 1</a>
</li>
<li class="nav-item d-none d-sm-block d-md-none">
<a class="nav-link" href="#">Item 2</a>
</li>
</ul>
Using this method allows for items 1 and 2 to only appear after the display is set to small and below. While also hiding the originals at that same display size.
See the Information section of the navbar here. I'm trying to get it to float right. I used .pull-right like the Bootstrap docs say, but it isn't working.
I also tried messing around with Inspect Element and applying float: right !important; directly to the li, which didn't work, and then to the a, which also didn't work.
This is my code:
<div class="navbar"">
<div class="navbar-inner">
<ul class="nav">
<li class="divider-vertical"></li>
<li id="academics" class="dropdown main_college_nav_item">Academics <b class="caret"></b>
<ul class="dropdown-menu">
<li id="professors"><a>Professors</a></li>
<li id="classes"><a>Classes</a></li>
<li id="difficulty"><a>Difficulty</a></li>
<li id="major"><a>Majors</a></li>
</ul>
</li>
<li class="divider-vertical"></li>
<li id="living_environment" class="dropdown main_college_nav_item">Living Environment <b class="caret"></b>
<ul class="dropdown-menu">
<li id="campus"><a>Campus</a></li>
<li id="food"><a>Food</a></li>
<li id="housing"><a>Housing</a></li>
<li id="weather"><a>Weather</a></li>
<li id="safety"><a>Safety</a></li>
</ul>
</li>
<li class="divider-vertical"></li>
<li id="social_life" class="dropdown main_college_nav_item"><a class="dropdown-toggle" data-toggle="dropdown">Social Life <b class="caret"></b></a>
<ul class="dropdown-menu">
<li id="kids"><a>Kids/Atmosphere</a></li>
<li id="parties"><a>Parties</a></li>
</ul>
</li>
<li class="divider-vertical"></li>
<li id="information" class="main_college_nav_item"><a class="pull-right">Information <i class="icon-resize-vertical"> </i></a></li>
<li class="divider-vertical"></li>
</ul>
</div>
</div>
Use the below HTML instead of your HTML.
I have created Separate ul for the Information tab and floated to right.
Update: Working Demo
<div class="navbar">
<div class="navbar-inner">
<ul class="nav">
<li class="divider-vertical"></li>
<li id="academics" class="dropdown main_college_nav_item">Academics <b class="caret"></b>
<ul class="dropdown-menu">
<li id="professors" class="active"><a>Professors</a></li>
<li id="classes"><a>Classes</a></li>
<li id="difficulty"><a>Difficulty</a></li>
<li id="major"><a>Majors</a></li>
</ul>
</li>
<li class="divider-vertical"></li>
<li id="living_environment" class="dropdown main_college_nav_item">Living Environment <b class="caret"></b>
<ul class="dropdown-menu">
<li id="campus"><a>Campus</a></li>
<li id="food"><a>Food</a></li>
<li id="housing"><a>Housing</a></li>
<li id="weather"><a>Weather</a></li>
<li id="safety"><a>Safety</a></li>
</ul>
</li>
<li class="divider-vertical"></li>
<li id="social_life" class="dropdown main_college_nav_item"><a class="dropdown-toggle" data-toggle="dropdown">Social Life <b class="caret"></b></a>
<ul class="dropdown-menu">
<li id="kids"><a>Kids/Atmosphere</a></li>
<li id="parties"><a>Parties</a></li>
</ul>
</li>
<li class="divider-vertical"></li>
</ul>
<ul class="nav pull-right">
<li class="divider-vertical"></li>
<li id="information" class="main_college_nav_item"><a>Information <i class="icon-resize-vertical"> </i></a></li>
</ul>
</div>
</div>