Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How I can center a block vertically and horizontally with Bootstrap?

I have this form:

<div class="container-fluid">
<div class="span5 well">
<h2>Authentification</h2>
<form method="POST">...</form>
</div>
</div>

How I can center that block (div span5 well) vertically and horizontally? Thank you.

like image 366
Julika Avatar asked Dec 09 '11 08:12

Julika


People also ask

How do I center a div vertically and horizontally in bootstrap?

To center a div horizontaly and vertically in Bootstrap, add the utlity class d-flex and justify-content-center , align-items-center to the div element class attribute. “justify-content-center” centers the div horizontally. “align-items-center” centers the div vertically.

How do you align horizontally and vertically centered?

For vertical alignment, set the parent element's width / height to 100% and add display: table . Then for the child element, change the display to table-cell and add vertical-align: middle . For horizontal centering, you could either add text-align: center to center the text and any other inline children elements.

How do you center a div both horizontally and vertically?

You can do this by setting the display property to "flex." Then define the align-items and justify-content property to “center.” This will tell the browser to center the flex item (the div within the div) vertically and horizontally.

How do I center a block element in bootstrap?

Use class center-block to set an element to center.


2 Answers

Horizontal centering can be done by adding margin: 0 auto to an element that has no siblings.

like image 58
Wex Avatar answered Nov 01 '22 17:11

Wex


<style>
.well
{       
    position:absolute;      
    width:200px;    
    height:200px;
    top: 50%;
    left: 50%;
    margin-top:-100px; /* negative number 1/2 height */
    margin-left:-100px; /* negative number 1/2 width */
    outline:1px solid #CCC;
}
</style>

<div class="container-fluid">
<div class="span5 well">
<h2>Authentification</h2>
<form method="POST">...</form>
</div>
</div>
like image 22
Zul Avatar answered Nov 01 '22 17:11

Zul