Bootstrap Tutorial - Forms on Bootstrap Navigation Bar








A simple form on Navigation bar

To properly style and position a form within the navbar, add the appropriate classes as shown below. For a default form, include .navbar-form and either .pull-left or .pull-right to properly align it.

<!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><!-- ww  w.j  a  v a 2  s  .  c o m-->
<body style='margin:20px;'>

  <div class="navbar">
     <form class="navbar-form pull-left">
       <input type="text" class="form-control" style="width: 200px;">
       <button type="submit" class="btn btn-default">Submit</button>
     </form>
  </div>


</body> 
</html>

Click to view the demo