logo Randthemes.com

How to center div in another div

If you need to center one div in another and you are wondering how to do this here is answer.

By using pure css you can do this. Here is our example of the code using bellow.


We are using this CSS code to do it.

position: relative;

.center-div {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;

.center-div:before {
content: ' ';
display: inline-block;
vertical-align: middle;
height: 100%;

.center-div .div-text {
border: 1px solid #000;
vertical-align: middle;
display: inline-block;

Leave a Reply