Archive for April 2007

HowTo: Center of the elements

Center of an element is very simply, but many beginners have problems with it. I was asked about it many times and that’s why I would like to present you a little HowTo:

<body style=”text-align:center;”>
<div style=”position:absolute; top:50%; margin-top:-50px; height:50px;
left:50%; width:100px; margin-left:-50px;” >
<div style=”position:absolute; text-align:center;”>
<div style=”height:100px; width:100px; background:red;”></div>
</div>
</div>

Attention: the value of margin-top should be a 50% of height-value and value of margin-left = 50% of with.