Showing 'active' tab on navigation - html

I'm trying to show the active tag on my nav bar. It shows on all tabs EXCEPT one with a drop-down. I can't figure out why its not calling the class on this particular button. I'm obviously placing it in the wrong place. Any help with this issue would be much appreciated!
Code: (The first one is CORRECT - ie - index.php is currently active. Where do I place the code (class="active") to make the next button (WHAT WE DO) the active tab when clicked?
<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>
<ul class="list-inline">
<li class="active">
<i class="fa fa-home"> </i>HOME
</li>
<li class="dropdown" role="presentation">
WHAT WE DO <span class="caret"></span>
<ul class="dropdown-menu">
<li>QUALITATIVE</li>
<li>QUANTITATIVE</li>
</ul>
</li>
<li> WHERE WE WORK</li>
<li> OUR CLIENTS </li>
<li> CONTACT US</li>
</ul>
</nav>

If I understand you correctly, you need to check the URL. (In my demo I set it to a specific URL) Then, add a class to the li parent.
var page = 'whatwedo_qualitative.php';
var a = $('[href="' + page + '"]');
$('.dropdown').has(a).addClass('active');
<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-default">
<ul class="nav navbar-nav list-inline">
<li>
<i class="fa fa-home"> </i>HOME
</li>
<li class="dropdown" role="presentation">
WHAT WE DO <span class="caret"></span>
<ul class="dropdown-menu">
<li>QUALITATIVE</li>
<li>QUANTITATIVE</li>
</ul>
</li>
<li> WHERE WE WORK</li>
<li> OUR CLIENTS </li>
<li> CONTACT US</li>
</ul>
</nav>

you need a javascript code to add/remove active class to the a link pressed.. something like this:
$("a").click(function() {
//remove all active class from a elements
$(this).addClass("active"); //add the class to the clicked element
});
a similar functionality is here: Add and remove a class on click using jQuery?

Related

Dropdown menu is not being shown

I cannot find out why the dropdown menu does not work. I am completely new in web dev
enter image description here
Make sure you have added bootstrap CDN link like:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
Check this link for navbar with dropdown menu:
https://www.w3schools.com/bootstrap4/tryit.asp?filename=trybs_navbar_dropdown&stacked=h
Post your html and css here. I can see only html code in image
Make the dropdown-menu class div tag a ul tag and all the links that need to be dropdown-items in li tags. That should work I guess.
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Categories
<span class="caret"></span></a>
<ul class="dropdown-menu">
<li class="dropdown-item">Item 1</li>
<li class="dropdown-item">Item 2</li>
<li class="dropdown-item">Item 3</li>
</ul>
</li>

Dropdown menu inside of another drop down menu is not working

I'm having trouble getting a drop-down menu inside another dropdown menu to work. The first level dropdown works fine, but for the second level, when I click on the option for the dropdown menu (Learning Profiles) nothing happens... the menu fails to display.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-md-2">
<nav id="sideNavBar">
<ul class="nav nav-pills nav-stacked">
<li id="navBarTitle">MENU</li>
<li class="dropdown">
Children <span class="caret"></span>
<ul class="dropdown-menu">
<li>
Add Child
</li>
<li>
Archive/Delete Child
</li>
<li>
Children Details
</li>
<li class="dropdown">
Learning Profiles<span class="caret"></span>
<ul class="dropdown-menu">
<li>
Observations
</li>
<li>
Learning Outcomes
</li>
<li>
Photos
</li>
</ul>
</a>
</li>
</ul>
</li>
</ul>
</nav>
</div>
</div>
there is little change in the html
<div class="container">
<div class="row">
<div class="col-md-2">
<nav id="sideNavBar">
<ul class="nav nav-pills nav-stacked">
<li id="navBarTitle">MENU</li>
<li class="dropdown">
Children <span class="caret"></span>
<ul class="dropdown-menu">
<li>
Add Child
</li>
<li>
Archive/Delete Child
</li>
<li>
Children Details
</li>
<li class ="dropdown-submenu">
Learning Profiles<span class="caret"></span>
<ul class="dropdown-menu">
<li>
Observations
</li>
<li>
Learning Outcomes
</li>
<li>
Photos
</li>
</ul>
</a>
</li>
</ul>
</li>
</ul>
</nav>
</div>
</div>
and add the following css
.dropdown-submenu {
position: relative;
}
.dropdown-submenu .dropdown-menu {
top: 0;
left: 100%;
margin-top: -1px;
}
also you need to add javascript
$(document).ready(function(){
$('.dropdown-submenu a.test').on("click", function(e){
$(this).next('ul').toggle();
e.stopPropagation();
e.preventDefault();
});
});
working plunker : https://plnkr.co/edit/jjrowMvX3FJ7OAsFpiaA?p=preview

Cannot get this menu to show horizontal

I can't get this menu to show horizontal, I want it to show like the one on w3Schools (enter their page, and above, in the navbar there is an option with "MORE", so when you click it, it shows a big menu with many a lot of options.)
The CSS is the simple Bootstrap default one.
I can't get mine to do so. Here is the code I'm using:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown">
Extra Verification <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li class="dropdown-header">Provides Address, Status, Previous Names</li>
<li>Connecticut </li>
<li>Georgia </li>
<li>Louisiana</li>
<li>Vermont</li>
<li>New Mexico</li>
<li class="divider"></li>
<li class="dropdown-header">Provides Address and Status</li>
<li>Alabama</li>
<li>Alaska</li>
<li>Arkansas</li>
<li>Arizona</li>
<li>California</li>
<li>Colorado</li>
<li>Hawaii</li>
<li>Idaho</li>
<li>Maryland</li>
</ul>
</div>
So if I'm understanding correctly, you want the dropdowns to appear/disappear on click? You need jQuery to do that. With CSS you can make them appear/disappear on hover but not toggle on clicking.
You have to include jQuery and Bootstrap JavaScript into your page:
<!DOCTYPE html>
<html>
<head>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown">Extra Verification
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li class="dropdown-header">Provides Address, Status, Previous Names</li>
<li>Connecticut </li>
<li>Georgia </li>
<li>Louisiana</li>
<li>Vermont</li>
<li>New Mexico</li>
<li class="divider"></li>
<li class="dropdown-header">Provides Address and Status</li>
<li>Alabama</li>
<li>Alaska</li>
<li>Arkansas</li>
<li>Arizona</li>
<li>California</li>
<li>Colorado</li>
<li>Hawaii</li>
<li>Idaho</li>
<li>Maryland</li>
</ul>
</div>
</body>
</html>

Can't make menu navbar dropdown

I can't make a menu navbar dropdown, here's my code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active">Home
</li>
<li>tech
</li>
<li class="dropdown">
case <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li role="presentation"><a role="menuitem" href="#">In</a>
</li>
<li role="presentation"><a role="menuitem" href="#">Out</a>
</li>
</ul>
</li>
<li>staff
</li>
<li>gallery
</li>
<li>Contact
</li>
</ul>
</div>
I want to make the case become a dropdown menu, but I can't make the menu items "in" and "out" appear, what am I doing wrong?
Your scripts might not have properly loaded. I tested your codes and they work just fine. I only added the following lines to load the required files from external sources:
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>

Why does my bootstrap drop down menu look unformatted?

I'm learning bootstrap for the first time and the dropdown menu seems to be unformatted and doesn't look like the other menu options that I've made. Its also not appearing when clicked, but I followed a tutorial exactly. Any ideas on the problem or mistakes?
<html>
<head>
<title>Bootstrap Testing</title>
<link rel="stylesheet" type="text/css" href="">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>
<nav class='navbar navbar-inverse'>
<div class='container-fluid'>
<!--Logo-->
<div class='navbar-header'>
<a href="#" class='navbar-brand'>MY LOGO</a>
</div>
<!--Menu Items-->
<div>
<ul class='nav navbar-nav'>
<li class='active'>Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</div>
<!--drop down menu-->
<li class='dropdown'>
My Profile <span class="caret"></span>
<ul class="dropdown-menu">
<li>Friends</li>
<li>Photos</li>
<li>Settings</li>
</ul>
</li>
</div>
</nav>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.3.min.js" type="text/javascript"></script>
</body>
You need to place the <li class='dropdown'> within the <ul class='nav navbar-nav'>. (The presence of an <li> element without a parent list element should probably be cause for alarm in any case.)
So that part of your HTML should be shuffled to look like:
<!-- [...] -->
<!--Menu Items-->
<div>
<ul class='nav navbar-nav'>
<li class='active'>Home</li>
<li>About</li>
<li>Contact</li>
<!--drop down menu-->
<li class='dropdown'>
My Profile <span class="caret"></span>
<ul class="dropdown-menu">
<li>Friends</li>
<li>Photos</li>
<li>Settings</li>
</ul>
</li>
</ul>
</div>
<!-- [...] -->
Here's a Bootply of the revised code. Hope this helps! Let me know if you have any questions.
The bootstrap.min.js needs to come after you load jquery. I always like to start my documents with the basic template bootstrap shows here: http://getbootstrap.com/getting-started/#template
It makes it a lot easier to make sure I have everything loading and in the right order.
You will also want to move your dropdown li to be inside your ul with the "nav navbar-nav" class. Like this:
<ul class='nav navbar-nav'>
<li class='active'>Home</li>
<li>About</li>
<li>Contact</li>
<!--drop down menu-->
<li class='dropdown'>
My Profile <span class="caret"></span>
<ul class="dropdown-menu">
<li>Friends</li>
<li>Photos</li>
<li>Settings</li>
</ul>
</li>
</ul>