Email
Share

We Rock Your Web Forum » Markup Languages » CSS

CSS Center Div?

(2 posts)
  1. andy

    member
    Joined: Aug '09
    Posts: 15

    What's the best way to center a DIV using CSS?

    Posted 2 years ago #

  2. Posted 2 years ago
  3. cwd

    senior admin
    Joined: Jul '09
    Posts: 225

    The quickest way to center a DIV using CSS is the following:

    body {
    text-align: center;
    }

    #centeredDIV {
    margin: 0 auto;
    }

    There's other methods, but we recommend the above one for simplicity. Another one that works fell is the negative left margin method:

    #centeredDIV {
    width:500px;
    left:50%;
    margin-left:-250px;
    }

    Basically you want to give the DIV a negative left margin equal to half the width of the DIV.

    Posted 2 years ago #

RSS feed for this topic

Reply

(required)

Allowed markup: BBcode blockquote code em strong ul ol li font strike center u hr.
You can also put code in between backtick ( ` ) characters.