Dropdown Bootstrap does not work

Asked

Viewed 1,090 times

0

I had made a menu using Bootstrap and it was working perfectly, but I had to add a dropdown, and apparently it shows no errors... But nothing happens by clicking on the menu.

      [![<div class="ma][1]][1]sthead">
    <nav>
    <ul class="nav nav-justified">
        <li><a href="index.html">Home</a></li>
        <li><a href="about.html">About</a></li>
        <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Products<span class="caret"></span></a></li>
                    <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
          <li class="active"><a href="#">Action</a></li>
          <li><a href="#">Another action</a></li>
          <li><a href="#">Something else here</a></li>
          <li role="separator" class="divider"></li>
          <li><a href="#">Separated link</a></li>
                    </ul>
        <li><a href="buy.html">Where to Buy</a></li>
        <li><a href="#">Contact Us</a></li>
      </ul>
    </nav>
  </div>

The bootstrap . css and . js files are also correctly pointed to the page.

<link rel="stylesheet" type="text/css" href="css/bootstrap.css">

1 answer

3


It doesn’t work because you added the dropdown menu out of the element li. Just insert it that will work perfectly.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />

<div class="ma][1]][1]sthead">
  <nav>
    <ul class="nav nav-justified">
      <li><a href="index.html">Home</a></li>
      <li><a href="about.html">About</a></li>
      <li class="dropdown">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Products<span class="caret"></span></a>
        <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
          <li class="active"><a href="#">Action</a></li>
          <li><a href="#">Another action</a></li>
          <li><a href="#">Something else here</a></li>
          <li role="separator" class="divider"></li>
          <li><a href="#">Separated link</a></li>
        </ul>
      </li>

      <li><a href="buy.html">Where to Buy</a></li>
      <li><a href="#">Contact Us</a></li>
    </ul>
  </nav>
</div>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.