View Full Version : How to vertically and horizontally center a div w/o absolute positioning

04-08-2011, 01:54 PM

I know about margin: auto but that seems to only work for horizontal center.

How would I vertically center?

And yes, I've looked up a lot of tutorials on the web but they all say you have to use absolute positioning which is a clumsy solution.

04-08-2011, 03:11 PM
See http://www.wpdfd.com/editorial/thebox/deadcentre4.html

Err.. without absolute position? Absolute position is not as clumsy as you feel. Situations are there where no other method of positioning would do the tricks and this is one of them.

In fact, all CSS properties might be clumsy, when we use them in wrong contexts.

04-08-2011, 06:12 PM
Hello ptrcao,
Yes, nothing wrong with the absolute positioned method (http://nopeople.com/CSS%20tips/vertical%20center%20with%20CSS/pg2.html). It's simple and works very well in all modern browsers.

Here is a method without absolute positioning (http://nopeople.com/CSS%20tips/vertical%20center%20with%20CSS/page4.html) that also works well.

04-09-2011, 01:18 AM
Thanks ab and excav. That solution will do. =)

btw ab, how do you put a red border around your edits?

04-09-2011, 10:05 AM
how do you put a red border around your edits?
There's an ][/COLOR] tag in the BBCode. See http://www.codingforums.com/misc.php?do=bbcode#edit