How to put a dropdown menu on a navigation bar using bootstrap?

Asked

Viewed 1,499 times

1

I know very little about css and am having a hard time putting a dropdown menu in the navigation bar of a page.

I have several links in this navigation bar and needed to open a menu with a list of other options by clicking on an item.

HTML:

<!-- Collect the nav links, forms, and other content for toggling -->
      <div class="collapse navbar-collapse navbar-ex1-collapse">
        <ul class="nav navbar-nav navbar-right">
          <li class="dropdown active">
            <a href="index.html">Inicio </a>

            <ul class="dropdown-menu">
              <li class="active">
                  <a href="index.html">Home</a>
              </li>
            </ul>
          </li>

           </ul>
      </div><!-- /.navbar-collapse -->

CSS:

.color-links a{
color: #000;
text-decoration: none;
}
.color-links a:hover{
color: #fff;
}
.itens-lista{

width: 24%;
margin-right: 11px;

}

.nav-tabs{
border-bottom: none;
}
.nav-tabs>li.active>a, .nav-tabs>li.active>a:focus, .nav-tabs>li.active>a:hover{
border: none;
background-color: #ee7e4b;
}

    .nav>li>a:focus, .nav>li>a:hover{
background-color: #ee7e4b;
border: none;
}

.topo-fone{
text-align:right; 
font-size:18px;
margin-top: 5px;

}

    @media (max-width: 767px) {

.topo-fone{
text-align: center;
}

.itens-lista{

width: 50%;
margin-right: 0px;

}

}

1 answer

1

If you are using bootstrap just follow the official documentation. It would look something like this:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">


<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<nav class="navbar navbar-default">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
        <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-brand" href="#">Brand</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 class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
        <li><a href="#">Link</a></li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><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>
            <li role="separator" class="divider"></li>
            <li><a href="#">One more separated link</a></li>
          </ul>
        </li>
      </ul>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>

http://getbootstrap.com/components/#navbar

Browser other questions tagged

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