?
Solved

Dropdown in Bootstrap nav not working

Posted on 2014-11-06
10
Medium Priority
?
4,312 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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 82

Accepted Solution

by:
David Johnson, CD, MVP earned 2000 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

Major Serverless Shift

Comparison of major players like AWS, Microsoft Azure, IBM Bluemix, and Google Cloud Platform

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses

770 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