The problem is,
Best way to center a <div> element on a page both vertically and horizontally?
Basically, margin-left: auto; margin-right: auto; will center on the horizontal, but what is the best way to do it vertically, too?
This solution is the best and most flexible way for center a div ( css center div)
You can check the demo on dabblet.com
The main trick in this demo is that in the normal flow of elements going from top to bottom, so the margin-top: auto is set to zero. However, an absolutely positioned element acts the same for distribution of free space, and similarly can be centered vertically at the specified top and bottom (does not work in IE7).
This trick will work with any sizes of div.
It is the another Simplest technique to center a div ( css center div) (This method has its implications though, but if you only need to center element regardless of flow of the rest of the content, it’s just fine.)
This will center element horizontally and vertically too. No negative margins, just power of transforms.
In this solution, there are two ways to to center a div ( css center div) through CSS.