Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to center form in bootstrap 3

How can I center my login form ? I'm using bootstrap column but it's not working.

Here is my code:

<div class="container">     <div class="row">         <div class="col-md-4 col-md-offset-6">             <h2>Log in</h2>                <div>                 <table>                     <tr>                         <td>1</td>                         <td>1</td>                     </tr>                     <tr>                         <td>2</td>                         <td>2</td>                     </tr>                     <tr>                         <td>3</td>                         <td>3</td>                     </tr>                  </table>              </div>          </div>     </div> </div> 
like image 945
mskuratowski Avatar asked Dec 31 '13 06:12

mskuratowski


People also ask

How do I center align a form?

Use the CSS text-align Property to Center a Form in HTML We can set the value to center to center the form. For example, apply the text-align property to the form tag in the style attribute, and set the property to center . Next, create input tags with the type text and then submit .

How do I center a form in Bootstrap 5?

To center a div on the page, you need to set the width of your container, then apply margin:0 auto; to it and it will center left and right on the page. If you want to center text, just add text-center to the class of the div your text is in. Bootstrap will do the rest.


2 Answers

There is a simple way of doing this in Bootstrap. Whenever I need to make a div center in a page, I divide all columns by 3 (total Bootstrap columns = 12, divided by 3 >>> 12/3 = 4). Dividing by four gives me three columns. Then I put my div in middle column. And all this math is performed by this way:

<div class="col-md-4 col-md-offset-4">my div here</div> 

col-md-4 makes one column of 4 Bootstrap columns. Let's say it's the main column. col-md-offset-4 adds one column (of width of 4 Bootstrap column) to both sides of the main column.

like image 156
Sid Avatar answered Sep 21 '22 06:09

Sid


A simple way is to add

.center_div{     margin: 0 auto;     width:80% /* value of your choice which suits your alignment */ } 

to you class .container.Add width:xx % to it and you get perfectly centered div!

eg :

<div class="container center_div"> 

but i feel that by default container is centered in BS!

like image 43
NoobEditor Avatar answered Sep 18 '22 06:09

NoobEditor