Solved

Dropdown in Bootstrap nav not working

Posted on 2014-11-06
10
3,884 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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 79

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
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…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

777 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