Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Align the components with Bootstrap

I want to align the components in Bootstrap. Which class should I use to achieve this:


1 Answer
Lakshmi Srinivas

To align the components like nav links, forms, buttons, or text to left or right in a navbar using the utility classes .navbar-left or .navbar-right. Both classes will add a CSS float in the specified direction.

You can try to run the following code to align components

Example

Live Demo

<!DOCTYPE html>
<html>
   <head>
      <title>Bootstrap Example</title>
      <link href = "/bootstrap/css/bootstrap.min.css" rel = "stylesheet">
      <script src = "/scripts/jquery.min.js"></script>
      <script src = "/bootstrap/js/bootstrap.min.js"></script>
   </head>
   <body>
      <nav class = "navbar navbar-default" role = "navigation" style="background: orange;">
         <div class = "navbar-header">
            <a class = "navbar-brand" href = "#">Alignment</a>
         </div>
         <div>
            <!--Left Align-->
            <ul class = "nav navbar-nav navbar-left">
               <li class = "dropdown">
                  <a href = "#" class = "dropdown-toggle" data-toggle = "dropdown">
                     Java
                     <b class = "caret"></b>
                  </a>
                  <ul class = "dropdown-menu">
                     <li><a href = "#">jmeter</a></li>
                     <li><a href = "#">EJB</a></li>
                     <li><a href = "#">Jasper Report</a></li>
                     <li class = "divider"></li>
                     <li><a href = "#">Separated link</a></li>
                     <li class = "divider"></li>
                     <li><a href = "#">One more separated link</a></li>
                  </ul>
               </li>
            </ul>
            <form class = "navbar-form navbar-left" role = "search">
               <button type = "submit" class = "btn btn-default">Left align-Submit Button</button>
            </form>
            <p class = "navbar-text navbar-left">Left align-Text</p>
            <!--Right Align-->
            <ul class = "nav navbar-nav navbar-right">
               <li class = "dropdown">
                  <a href = "#" class = "dropdown-toggle" data-toggle = "dropdown">
                     Java
                     <b class = "caret"></b>
                  </a>
                  <ul class = "dropdown-menu">
                     <li><a href = "#">jmeter</a></li>
                     <li><a href = "#">EJB</a></li>
                     <li><a href = "#">Jasper Report</a></li>
                     <li class = "divider"></li>
                     <li><a href = "#">Separated link</a></li>
                     <li class = "divider"></li>
                     <li><a href = "#">One more separated link</a></li>
                  </ul>
               </li>
            </ul>
            <form class = "navbar-form navbar-right" role = "search">
               <button type = "submit" class = "btn btn-default">
                  Right align-Submit Button
               </button>
            </form>
            <p class = "navbar-text navbar-right">Right align-Text</p>
         </div>
      </nav>
   </body>
</html>
Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.