It's very simple, really.
It's all done with positioning.
Assume that you have the following markup:
Code:
<div id='container'>
<div id='aligned'></div>
</div>
Apply the following CSS:
Code:
div#container {
position: relative;
height: 600px;
border: 1px solid gold;
}
div#aligned {
position: absolute;
border: 1px solid yellow;
background: lightyellow;
width: 200px;
height: 200px;
top: 50%;
left: 50%;
margin: -101px 0 0 -101px;
}
This assumes that your container either has a height larger than the positioned child naturally, or you've set a fixed height for it that's larger than the height of the positioned child. You can also just do away with the container, and the child will be centered vertically and horizontally respective to the browser's viewport.
The theory is pretty simple, you give the absolutely positioned child a fixed width and height of some kind, then adjust its top and left margins negatively by exactly half of it's width and height (taking borders and padding into account). So if you have a collective height of 202 pixels (200-pixel height and 2-pixel border), you adjust the top margin by -101px. And the same for the width. And the same technique works for images, paragraphs, etc. Won't work on tables because tables cannot be positioned.
HTH!
Regards,
Rich
--
Author,
Beginning CSS: Cascading Style Sheets For Web Design, 2nd Edition
CSS Instant Results
http://www.catb.org/~esr/faqs/smart-questions.html