InterviewSolution
Saved Bookmarks
| 1. |
Center an element in Bootstrap |
|
Answer» The CENTER-block BOOTSTRAP class is useful in CHANGING the position of an element to center. The class APPLIES the following to center an element: display:block margin-right:auto margin-left:autoThe following is an example that floats an element in the center in Bootstrap 3: <!DOCTYPE html> <html> <head> <meta name="viewport" CONTENT="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> </head> <body> <div class="container"> <h2>Floating an element</h2> <div class="center-block" style="background-color:red;color: white;width:100px;"> This is in the center! </div> </div> </body> </html>The output: Bootstrap 4 came with the concept of flex. Using flex, you can easily center an element with.align-self-center class. |
|