Brae Brae - 1 year ago 99
CSS Question

Vertical align a block

How on earth do you center a div vertically?

Horizontal has enough ways already, but no matter what i try, vertical centering is just impossible.

body { vertical-align: middle;}

Does nothing

body {text-align: middle;}

Does nothing

div.middle {top: 50%;}

Does nothing

Is it even possible?

I think i'm gonna cry.

Answer Source

See Vertical Centering in CSS.

  <title>Universal vertical center with CSS</title>
    .greenBorder {border: 1px solid green;} /* just borders to ser it */

  <div class="greenBorder" style="display: table; height: 400px; #position: relative; overflow: hidden;">
    <div style=" #position: absolute; #top: 50%;display: table-cell; vertical-align: middle;">
      <div class="greenBorder" style=" #position: relative; #top: -50%">
        any text<br>
        any height<br>
        any content, for example generated from DB<br>
        everything is vertically centered
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download