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>
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 .
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.
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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With