Here's a cool technique for centering the box both vertically and horizontally:
Container
- must have
display: table;
Inner container
- must have
display: table-cell; - must have
vertical-align: middle; - must have
text-align: center;
Content field
- must have
display: inline-block; - , .
text-align: left; text-align: right;, ,
, , !
.
Demo
body {
margin : 0;
}
.outer-container {
position : absolute;
display: table;
width: 100%;
height: 100%;
background: #ccc;
}
.inner-container {
display: table-cell;
vertical-align: middle;
text-align: center;
}
.centered-content {
display: inline-block;
text-align: left;
background: #fff;
padding : 20px;
border : 1px solid #000;
}
<div class="outer-container">
<div class="inner-container">
<div class="centered-content">
<p>You can put anything here</p>
<p>Yes, really anything!</p>
</div>
</div>
</div>
. !