...

View Full Version : Center a div vertically in another div



mattshiao
08-10-2010, 02:10 AM
Hi,

I am sure this question was asked more than 100 times but I still can not find a simple answer, how to center a Div vertically inside another Div?

One of my colleagues told me to use padding to push the inner Div to center, I don't think it's a good idea, please do not give me the same answer.

TIA

jimhill
08-10-2010, 02:45 AM
Try this.

<div style="position: relative; width:200px; height:200px; background-color:blue;">
<div style="position: absolute; width:100px; height:100px; top: 50%; margin-top: -50px; background-color:red;">
Centered Box
</div>
</div>

optimus203
08-10-2010, 03:41 AM
This link (http://www.jakpsatweb.cz/css/css-vertical-center-solution.html) might help out as well.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum