My Personal Blog

Hi, my names Danny and I am a webmaster from Leeds, UK.

Every now and then, I come across a small but valuble piece of web design information that helps me with my work. So I thought I might as well share these tips with the rest of you webmasters!

So I hope these tips can help you in some way....

Wednesday, 1 August 2007

Centering divs/Centering your page

People often ask questions about centering divs, or how can I center my page?

Well there a fair few centering techniques out there, but heres one I find particularly useful.

It supports skinny web designs, that is sites that don't use the entire screen. Usually, these pages' HTML is set out so that there is a wrapper div (or a containing div) around the rest of the divs and content. This is the div that you need to center.

The way I go about it is to give the wrapper div a percentage value, we'll use 80% in this example. Then, take the remaining percentage (in this case 20%) and half it (10%.... obviously :D). Then give the wrapper div a left-margin of 10% (or whatever number you came up with).

Now the wrapper div will always appear centered, and therefore all of the inner divs will be centered along with it!

2 comments:

Smartphone said...

Hello. This post is likeable, and your blog is very interesting, congratulations :-). I will add in my blogroll =). If possible gives a last there on my blog, it is about the Smartphone, I hope you enjoy. The address is http://smartphone-brasil.blogspot.com. A hug.

CMasterson.com said...

Dear Smartphone,

Such a smart and clever post. Almost likable. Such smart and clever smileys.