Vertical & Horizontal Centering of 'div' object
The keystone of this solution is that the internal object is absolutely positioned in half of its parent's area height and then is moved up by half of its height. Similarly half of its parent's area width and then moved left by half of its width.
Firefox and Netscape does not support 'pixel' property, so in order to work the codes on FF and N, you need to use parseInt() for getting the numeric portion of the size i.e. size without 'px'.
After download the codes replace the following lines:
with these one:
Using the code
Run the attached sample file 'centering_div.aspx', which contains the complete example.
h = document.getElementById(Child).offsetHeight;
w = document.getElementById(Child).offsetWidth;
Created by: Muhammad Shoaib
Created on: 10-10-2007