Center any element in Bootstrap


Use the .center-block class in Bootstrap to center an element.

You can try to run the following code to implement the .center-block class:

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>
      <div class = "container">
         <h1>Heading One</h1>
         <div class = "center-block" style = "background-color:green;color: white; width:200px;">Text will be in center.</div>
      </div>
   </body>
</html>

Updated on: 12-Jun-2020

171 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements