Reputation: 276
I have created a dropdown menu but it is not working:
<div class="col-xs-6 col-md-4">
<ul id="hld" style="margin-top:10px;">
<li class="dropdown" style="border:1px solid #333;padding:5px;text-align:center;">
<a href="/a/home.html" class="dropdown-toggle">Menu</a>
<ul class="dropdown-menu">
<li><a href="/cat/b.html">Tom</a></li>
<li><a href="/cat/c.html">Greg</a></li>
<li><a href="/cat/d.html">Jane</a></li>
</ul>
</li>
</ul>
</div>
I am using Bootstrap CSS framework and have included all the appropriate CSS and JS files. What am I doing wrong? While looking at other questions similar to mines, I haven't been able to figure it out.
Upvotes: 0
Views: 50
Reputation: 21663
You're missing some key elements.
This is what your dropdown element should look like.
<li class="dropdown" style="border:1px solid #333;padding:5px;text-align:center;">
This goes with the dropdown-toggle class.
data-toggle="dropdown" aria-expanded="false"
<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.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div class="col-xs-6 col-md-4">
<ul id="hld" style="margin-top:10px;">
<li class="dropdown" style="border:1px solid #333;padding:5px;text-align:center;"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false">Menu <span class="caret"></span></a>
<ul class="dropdown-menu ">
<li><a href="/cat/b.html ">Tom</a>
</li>
<li><a href="/cat/c.html ">Greg</a>
</li>
<li><a href="/cat/d.html ">Jane</a>
</li>
</ul>
</li>
</ul>
</div>
Upvotes: 1
Reputation: 291
First mistake was a couple of quotation marks missing. On top of that, you are not following the syntax and classes listed here: http://getbootstrap.com/components/#dropdowns
Here is the correct version:
<div class="col-xs-6 col-md-4">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
Menu
<span class="caret"></span>
</button>
<ul id="hld" class="dropdown-menu" style="margin-top:10px;">
<li><a href="/cat/b.html">Tom</a></li>
<li><a href="/cat/c.html">Greg</a></li>
<li><a href="/cat/d.html">Jane</a></li>
</ul>
</div>
Upvotes: 0
Reputation: 111
One solution may be that you are not referencing the jquery.js source before bootstrap.js source
Upvotes: 2