Center container DIV vertically

Discussion in 'CSS' started by Abh, Apr 29, 2010.

  1. #1
    Hi.

    I know how to center it horizontally, with margin:0 auto, but how do you also center it vertically?
     
    Abh, Apr 29, 2010 IP
  2. ampg-it

    ampg-it Peon

    Messages:
    75
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi

    This should do it.

    #div {
    	position: absolute;
    	top: 50%;
    }
    Code (markup):
     
    ampg-it, Apr 29, 2010 IP
  3. Abh

    Abh Active Member

    Messages:
    162
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    60
    #3
    thank you for the feedback.
    i've googled it and reached the same solution, still, it seems i have some code problems, cause when i place that code it looks like this: http://abhdesign.5com.ro/
     
    Abh, Apr 29, 2010 IP
  4. ampg-it

    ampg-it Peon

    Messages:
    75
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You'll probably need to adjust the top margin to something like 40%.

    You're best just playing around with it until it gets to where you want it.
     
    ampg-it, Apr 30, 2010 IP
  5. Abh

    Abh Active Member

    Messages:
    162
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    60
    #5
    I'm giving up on this, it doesn't seem like i'll get anywhere with it. Thing is that when i give it position:absolute it sticks to the left side of the screen.
    Thank anyway.
     
    Abh, Apr 30, 2010 IP
  6. webstar09

    webstar09 Guest

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    try the same thing like margin: 0 auto; but make it, keep changing the top settings until you have what you want

    #div {
    position: relative;
    margin: 0 auto;
    top: 0;
    }
     
    webstar09, Apr 30, 2010 IP