Centering a DIV using the negative margin method
The following CSS will center a DIV whih is 500px wide. This method is very clean and works in all browsers.
div {
position: absolute;
left: 50%;
width: 500px;
margin-left: -250px;
}
Change the width to suit your needs then change the margin-left to half the width of the div.
| Author |
: Paul Hayman |
| Published |
: Thursday, 21 June, 2007 |
Paul is the COO of kwiboo ltd consultant and has more than a decade of IT consultancy experience. He has consulted for a number of blue chip companies and has been exposed to the folowing sectors: Utilities, Telecommunications, Insurance, Media, Investment Banking, Leisure, Legal, CRM, Pharmaceuticals, Interactive Gaming, Mobile Communications, Online Services.
Paul is the COO and co-founder of kwiboo (http://www.kwiboo.com/) and is also the creator of GeekZilla.
Comments