...

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



ptrcao
04-08-2011, 01:54 PM
http://www.mathannotated.com/tests/about.html

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.

abduraooft
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.

Excavator
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.

ptrcao
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?

abduraooft
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum