Bootstrap Dropdown Not Un-Collapsing Menu

I've looked everywhere, but can't seem to find the answer to my solution. I am following a tutorial on how to make a navbar for my website and I am trying to make it mobile friendly as well. I want the navbar to display a button that un-collapses the menu on a smaller device. But even after I added jQuery, it still doesn't open the menu.

Here is my code that I have, hopefully it is just a simple fix that I am overlooking.

<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<title>Personal Website</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="styles/main.css">

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="">       </script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="">
<!-- Latest compiled and minified JavaScript -->
<script src=""></script>


<nav class="navbar navbar-inverse">
    <div class="container-fluid">
        <!-- Logo -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="mainNavbar">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            <a href="#" class="navbar-brand">Test</a>

        <!-- Menu Items -->
        <div class="collapse navbar-collapse" id="mainNavbar">
            <ul class="nav navbar-nav">
                <li class="active"><a href="#">Home</a> </li>
                <li><a href="#">About</a> </li>
                <li><a href="#">Contact</a> </li>

                <!-- Drop Down Menu -->
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">My Profile <span class="caret"></span></a>
                    <ul class="dropdown-menu">
                        <li><a href="#">About</a> </li>
                        <li><a href="#">Contact</a> </li>

            <!-- Right Align -->
            <ul class="nav navbar-nav navbar-right">
                <li><a href="#">Logout</a> </li>


Thanks for the help in advance!

Answers 1

  • there is a mistake in your button. you forgot to place the # in your data-target attribute.

    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#mainNavbar">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>

Related Articles