how to make the div exactly in center ?

Discussion in 'CSS' started by hansab, Apr 5, 2010.

  1. #1
    I would like to make my div exactly in center, no matter what browser size is, it should be in center in width and length as well. Please help.
     
    hansab, Apr 5, 2010 IP
  2. GameInfiniti

    GameInfiniti Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    well if it's just a 1 layered div that should be ez.

    html:
    <div id="center">THIS SHOULD WORK, TESTED IN CHROME,FIREFOX, and IE</div>
    Code (markup):
    css:
    body {text-align:center;} {#center {width:(specific)px; margin:auto; text-align:left;}
    Code (markup):
     
    GameInfiniti, Apr 5, 2010 IP
  3. moodey-aimee

    moodey-aimee Guest

    Messages:
    152
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    margin: 0 auto;

    Put this in your div tag on your Css. that would work ^__^
     
    moodey-aimee, Apr 7, 2010 IP
  4. pixelz

    pixelz Greenhorn

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #4
    try this:
    .centeredDivContainer{display:block;width:250;margin:auto;text-align:left;}
     
    pixelz, Apr 10, 2010 IP
  5. JustCause

    JustCause Guest

    Messages:
    192
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Im not sure if you mean in the center just horizontally or horizontally and vertically so here is both

    HORIZONTAL AND VERTICAL CENTERING

    #center {
    margin-left:auto;
    margin-right:auto;
    margin-top:auto;
    margin-right:auto;
    text-align:center;
    }
    Code (markup):
    HORIZONTAL CENTERING

    #center {
    margin-left:auto;
    margin-right:auto;
    text-align:center;
    }
    Code (markup):
     
    JustCause, Apr 24, 2010 IP