Bootstrap Tutorial - Bootstrap Button dropdown menus








Pop down menus

Use any button to trigger a dropdown menu by placing it within a .btn-group and providing the proper menu markup.

The following code turns a button into a dropdown toggle with some basic markup changes.

<!DOCTYPE HTML>
<html> 
<head> 
<link href="http://java2s.com/style/bootstrap.min.css" rel="stylesheet">
<!--  www .j  av a  2s  .c o  m-->
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script src="http://java2s.com/style/bootstrap.min.js"></script>

</head>
<body style='margin:20px;'>

<!-- Single button -->
<div class="btn-group">
  <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
    Action <span class="caret"></span>
  </button>
  <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 class="divider"></li>
    <li><a href="#">Separated link</a></li>
  </ul>
</div>
    
</body> 
</html>

Click to view the demo





Change the button style to primary.

<!DOCTYPE HTML>
<html>
<head>
<link href="http://java2s.com/style/bootstrap.min.css" rel="stylesheet">
<!-- w ww  . ja  va 2  s. c o  m-->
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script src="http://java2s.com/style/bootstrap.min.js"></script>

</head>
<body style='margin: 20px;'>

  <div class="btn-group">
    <button type="button" class="btn btn-primary dropdown-toggle"
      data-toggle="dropdown">
      Action <span class="caret"></span>
    </button>
    <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 class="divider"></li>
      <li><a href="#">Separated link</a></li>
    </ul>
  </div>

</body>
</html>

Click to view the demo





Mark the button as danger.

<!DOCTYPE HTML>
<html>
<head>
<link href="http://java2s.com/style/bootstrap.min.css" rel="stylesheet">
<!-- w  ww  .ja v a 2s. co  m-->
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script src="http://java2s.com/style/bootstrap.min.js"></script>

</head>
<body style='margin: 20px;'>

  <button type="button" class="btn btn-danger dropdown-toggle"
    data-toggle="dropdown">
    Danger <span class="caret"></span>
  </button>

</body>
</html>

Click to view the demo

Warning button dropdown

<!DOCTYPE HTML>
<html>
<head>
<link href="http://java2s.com/style/bootstrap.min.css" rel="stylesheet">
<!--   w ww .j a  v a  2 s  . c  o m-->
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script src="http://java2s.com/style/bootstrap.min.js"></script>

</head>
<body style='margin: 20px;'>

  <button type="button" class="btn btn-warning dropdown-toggle"
    data-toggle="dropdown">
    Danger <span class="caret"></span>
  </button>

</body>
</html>

Click to view the demo

Success button.

<!DOCTYPE HTML>
<html>
<head>
<link href="http://java2s.com/style/bootstrap.min.css" rel="stylesheet">
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script src="http://java2s.com/style/bootstrap.min.js"></script>
</head><!-- w  ww .java  2 s  .  com-->
<body style='margin: 20px;'>

  <button type="button" class="btn btn-success dropdown-toggle"
    data-toggle="dropdown">
    Danger <span class="caret"></span>
  </button>

</body>
</html>

Click to view the demo