2

Possible Duplicate:
Using jQuery to center a DIV on the screen

I know it works with table, but nowdays there is no way to auto vertical align (in the center) text? I can't believe it...

My code :

HTML

<div class="content">
    This is my text
</div>​

CSS

.content
{
    width:80px;
    height:150px;    
    background-color:#aeaeae;
}
Community
  • 1
  • 1
markzzz
  • 47,390
  • 120
  • 299
  • 507

3 Answers3

4

Add display: table-cell; vertical-align: middle; to your div, demo: little link.

For this to work on IE7, you can use this: another little link. It detects when your browser is IE6/7, and replaces elements with display: table-*; with actual HTML tables.

Chris
  • 26,544
  • 5
  • 58
  • 71
1

Here's a site with multiple options and the assessments of each. I've used the table based one with good success.

http://css-tricks.com/vertically-center-multi-lined-text/

Matt Whipple
  • 7,034
  • 1
  • 23
  • 34
  • SO answers should be more "self-contained", not dependent upon the status of external links to stay useful. – Sparky Sep 26 '12 at 13:43
0
.content
{
    width:80px;
    height:150px;    
    background-color:#aeaeae;
    display:table-cell;
    vertical-align:middle;
}

This should help

dan_fides
  • 324
  • 1
  • 10