Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Page 1 of 2 12 LastLast
Results 1 to 10 of 17
  1. #1
    Join Date
    May 2006
    Location
    Hull
    Posts
    7,701
    Tokens
    2,430
    Habbo
    Moh

    Latest Awards:

    Default Best way of Vertical centering a div?

    What's the best way to vertical center a div?

    +rep

  2. #2
    Join Date
    Oct 2008
    Posts
    27
    Tokens
    0

    Default

    I am learning to code, but could you do in the css. margin-top: 25%; or 50% or something. LOL im probs wrong !
    Who me? O'rly:eusa_whis

  3. #3
    Join Date
    Jun 2008
    Location
    Manchester
    Posts
    766
    Tokens
    0

    Default

    I've heard people say:
    Code:
    margin: auto;
    but I've not tryed that yet. I know this works:
    Code:
    position: absolute;
    top: 50%;
    margin top: -[half div's height]px;
    CSS obviously.

  4. #4
    Join Date
    May 2006
    Location
    Hull
    Posts
    7,701
    Tokens
    2,430
    Habbo
    Moh

    Latest Awards:

    Default

    Quote Originally Posted by Jxhn View Post
    I've heard people say:
    Code:
    margin: auto;
    but I've not tryed that yet. I know this works:
    Code:
    position: absolute;
    top: 50%;
    margin top: -[half div's height]px;
    CSS obviously.
    What if the height is expandable - sorry, forgot to state that.

  5. #5
    Join Date
    Sep 2007
    Location
    England
    Posts
    3,602
    Tokens
    500

    Latest Awards:

    Default

    When I asked before for alligning divs in a skin I got told to use

    v-align: center;
    The other day I was in a toilet.
    A voice came from the cubicle next to me: "Hello mate, how are you doing?"
    I didn't want to be rude, so I said, "Not too bad, thanks."
    I heard the voice again. "So, what are you up to?"
    Again I answered, "Just having a quick ****... How about yourself?"
    Then I heard him say "Sorry, mate, I'll have to call you back. I've got some **** in the cubicle next to me answering everything I say."

  6. #6
    Join Date
    Jun 2008
    Location
    Manchester
    Posts
    766
    Tokens
    0

    Default

    Quote Originally Posted by Jack120 View Post
    What if the height is expandable - sorry, forgot to state that.
    Then try the margin: auto; thing. If that doesn't work then you might need javascript to find the height of the element. I'm pretty sure It must be possible without javascript though.

    Quote Originally Posted by Favourtism View Post
    When I asked before for alligning divs in a skin I got told to use

    v-align: center;
    Thats an old html tag and can be done with css. I think you meant valign="middle". When I was looking for information about that I found a possible solution for Jack's problem.
    Code:
    div.blah
    {
    vertical-align: middle;
    }

  7. #7
    Join Date
    Aug 2005
    Location
    Newcastle
    Posts
    1,417
    Tokens
    0

    Latest Awards:

    Default

    use margin: auto; on the container div or even in the body tag.



  8. #8
    Join Date
    Sep 2005
    Location
    East London
    Posts
    3,028
    Tokens
    0

    Latest Awards:

    Default

    i swear theres vertical-align: in css

  9. #9
    Join Date
    Sep 2008
    Posts
    718
    Tokens
    0

    Default

    i think they are right.

    Code:
    #div {
    margin: auto;
    should work.

    but, you can try this:

    Code:
    <div style="background-image: url( '<your-full-image>.png' ); background-position: 50% center; background-repeat: no-repeat; width: <your-images-width>px; height: <your-images-width>px; position: absolute; top: 50%; left: 50%; margin-left: -( <your-images-width> / 2 )px; margin-top: -( <your-images-height> / 2 )px;"></div>
    +.net - omg it's coming o_o

  10. #10

    Default

    Jxhn is right to an extent in using vertical align, but for it to work you must set the parent/containing div to be display: table-cell; here is an example.

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    
    <style type="text/css">
    #container
    {
      width: 500px;
      height: 500px;
      display: table-cell;
      vertical-align: middle;
      background-color: #333;
    }
    
    #middle
    {
      width: 500px;
      background-color: #999;
    }
    </style>
    
    </head>
    <body>
    
    <div id="container">
      <div id="middle">
        Expands yay :)<br />
        <br />
        <br />
        <br />
        and yet still centered :P:
      </div>
    </div>
    
    </body>
    </html>
    Now if you want something centered vertically in the body now that's a different story.


    I might also add on Jxhn first post about the position: absolute; left: 50%; margin-left: -(width/2)px of course you don't do it like that you do the calculations this has one slight problem - you've got to set the parent to position: relative; otherwise it'll fail.
    Last edited by Iszak; 25-10-2008 at 09:02 PM.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •