Solved

Dropdown in Bootstrap nav not working

Posted on 2014-11-06
10
3,729 Views
Last Modified: 2014-11-10
gooddiabetesdiet.com/responsive/index2.html

on that page, I wanted to shorten the menu by adding a dropdown. As far as I can tell, I've done it correctly, and the top portion with the caret is there, but if I click on it, no dropdown appears. It seems that maybe I don't have the right CSS?

Thanks for your help.
0
Comment
Question by:mel200
  • 5
  • 3
10 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 40427151
You cannot fire a dropdown with a click event when the element being clicked is a link the link has priority.

if you want the dropdown to display either take the link off the top element of the menu or user hover with something like:

.dropdown-toggle:hover dropdown-menu{display:block;}

Cd&
0
 

Author Comment

by:mel200
ID: 40427434
Ok, will try that. This is the exact code given here: http://www.tutorialrepublic.com/twitter-bootstrap-tutorial/bootstrap-dropdowns.php They have:

            <li class="dropdown">

                <a href="#" data-toggle="dropdown" class="dropdown-toggle">Messages <b class="caret"></b></a>

                <ul class="dropdown-menu">

                    <li><a href="#">Inbox</a></li>

                    <li><a href="#">Drafts</a></li>

                    <li><a href="#">Sent Items</a></li>

                    <li class="divider"></li>

                    <li><a href="#">Trash</a></li>

                </ul>

            </li>
0
 

Author Comment

by:mel200
ID: 40427444
OK, I changed it to this, same problem:

    <li data-toggle="dropdown" class="dropdown dropdown-toggle btn btn-green">Diabetic Meals <b class="caret"></b></li>
                    <ul role="menu mainmenu" class="dropdown-menu">
                        <li><a href="living-with-diabetes.html">Living with Diabetes</a></li>
                        <li><a href="nutrition.html">Diabetic Nutrition</a></li>
                             <li><a href="good-diabetic-diet-news.html">Diabetic News</a></li>
                    </ul>
                </li>
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 40429441
I don't know how but you have now got 5 validation errors in the page right where the menu is and they are serious structural errors.  I can't make it any simpler or straight forward then the styling I gave you. Copy and paste from an example does not guarantee anything except that is works on the page where you found it.

Basically bootstrap has turned what would be a 10 minute fix in ordinary code into a major operation.

Take a look at my dropdown menu page and see if it helps seeing how to do it without all the bloated bootstrap junk in the way.

Cd&
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:mel200
ID: 40432683
Sorry, doesn't help me. I'm just not understanding it. I tried what you said to do, and it didn't work, so I'm not sure where to go from here.
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 40433431
I'm not sure where to either Mel.  I suspect that somewhere buried in the bloated bottscrap mess there is something that is either overriding or preventing the normal cascade.  The DOM has probably been damaged by the BS jquery, though it could be that one of the others is creating some kind of conflict.

The best approach at this point is probably to go through the jquery code and see if you can find the function that is breaking it.  Hopefully when you find it, you will be able to fix it without breaking something else.

Cd&
0
 
LVL 78

Accepted Solution

by:
David Johnson, CD, MVP earned 500 total points
ID: 40433485
change
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"
to
 <meta http-equiv="X-UA-Compatible" content="IE=edge>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example of Twitter Bootstrap 3 Dropdowns within a Navbar</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap-theme.min.css">
<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.0/js/bootstrap.min.js"></script>
<style type="text/css">
	.bs-example{
    	margin: 20px;
    }
</style>
</head>
<body>
<div class="bs-example">
    <nav id="myNavbar" class="navbar navbar-default" role="navigation">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="container">
            <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>
                <a class="navbar-Home href="#">Home</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><a href="#">About Us</a></li>
                    <li><a href="#">Menu</a></li>
	                <li><a href="#">Contact US</a></li>
                    <li><a href="#">FAQ</a></li>
                <ul class="nav navbar-nav navbar-right">
                    <li class="dropdown">
                        <a href="#" data-toggle="dropdown" class="dropdown-toggle">Diabetic Meals<b class="caret"></b></a>
                        <ul class="dropdown-menu">
                             <li><a href="living-with-diabetes.html">Living with Diabetes</a></li>
                        <li><a href="nutrition.html">Diabetic Nutrition</a></li>
                 		<li><a href="good-diabetic-diet-news.html">Diabetic News</a></li>                            <li class="divider"></li>
                        </ul>
                    </li>
                </ul>
            </div><!-- /.navbar-collapse -->
        </div>
    </nav>
</div>
</body>
</html>                

Open in new window

0
 

Author Comment

by:mel200
ID: 40433544
Thanks, that almost works!! I'll work on the one item that's too high, but we're close, thanks!
0
 

Author Closing Comment

by:mel200
ID: 40433553
Thanks! That works great!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Select2 jquery help 9 46
Scrolling the scrollbar in a list in html 9 33
Detecting robots? 5 35
CSS Divs in Safari 3 20
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now