Vertical align for div

Discussion in 'CSS' started by shadow12345, Nov 28, 2008.

  1. #1
    Anyknow knows of a way to align text inside a div vertically? I tried
    vertical-align: middle;
    but it didn't work at all, the text is still at top :(
     
    shadow12345, Nov 28, 2008 IP
  2. drhowarddrfine

    drhowarddrfine Peon

    Messages:
    5,428
    Likes Received:
    95
    Best Answers:
    7
    Trophy Points:
    0
    #2
    A <div> is a block level element but vertical-align only works on inline elements.
     
    drhowarddrfine, Nov 28, 2008 IP
  3. shadow12345

    shadow12345 Banned

    Messages:
    79
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    yup, but is there any way to align vertically in div?
     
    shadow12345, Nov 28, 2008 IP
  4. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #4
    Assuming you want to push it down, padding at the top expressed in pixels should do the job.

    This is easy to set in your css file. I have different padding for each identified div.
     
    Colbyt, Nov 28, 2008 IP
  5. shadow12345

    shadow12345 Banned

    Messages:
    79
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    If I want the stuff inside the divs to be dynamic (ie, php) not static, I am sure padding will not do the job alright :(
     
    shadow12345, Nov 28, 2008 IP
  6. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #6
    Centering one or more lines of text vertically in a box is not that difficult in modern browsers. It's IE that requires the sleight of hand and bits of legerdemain to pull it off. See my little tutorial, vertical centering of inline elements.

    cheers,

    gary
     
    kk5st, Nov 29, 2008 IP
  7. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #7
    The more dynamic content you have, particularly if you want sibling elements to be relational to each-other, the more likely it is you may be forced into using a table.

    CSS/DIV can do a good deal, but there are a number of things it cannot do.
     
    deathshadow, Nov 30, 2008 IP