Solved

Dropdown in Bootstrap nav not working

Posted on 2014-11-06
10
4,026 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
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
 

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 80

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime is disastrous for companies and can lead to major hits on a brand, reputation, an…
The viewer will learn how to dynamically set the form action using jQuery.
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…

733 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