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

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Blogosphere News
  • LinkArena
  • Live
  • MisterWong
  • MisterWong.DE
  • Technorati
  • Webnews.de
  • YahooMyWeb
  • Yigg

One Comment

  1. Idetrorce:

    very interesting, but I don’t agree with you
    Idetrorce

Leave a comment