Up to 70% off on hosting for WordPress Websites $2.95 /mo

Csshint recommends hosting
css html

Center div horizontally and vertically

In this post we are going to learn how to create center div horizontally and vertically Designed by Tipue.

Center div horizontally and vertically

Center div horizontally and vertically


HTML

[code language=”html”]

<div class="center-div"></div>
[/code]

CSS

[code language=”css”]
body
{
background-color: #fcfcfc;
}
.center-div
{
position: absolute;
margin: auto;
top: 0;
right: 0;
bottom: 0;
left: 0;
width: 100px;
height: 100px;
background-color: #ccc;
border-radius: 3px;
}

[/code]

Centering a div in a page, horizontally and vertically