Skip navigation
Currently Being Moderated

text centering issue is killing me!

Mar 19, 2013 8:52 PM

i know that you have all helped me with this before, but i still can't get it to work right.

 

how do i center text within a div, i can get it to center horizontally, but vertically i know that you use line-height, but it still isn't perfectly centered. my code can be found at http://www.coloredfortunecookies.com and it is the text within the .gobox that i want centered, please help!!!!

 
Replies
  • Currently Being Moderated
    Mar 20, 2013 12:51 AM   in reply to thefortunecookieguy

    You could try to increase the top padding using EMs rather than pixels. EMs allow the use of decimal points.

     

    It remains a matter of trial and error.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 20, 2013 1:49 AM   in reply to thefortunecookieguy

    line-height only work for a single lien of text.

     

    I just add an extra bit of top-padding to visually vertically center text in a <div>.

     

    You could also use display: table-cell; but I can't remember wich versions of IE that is not supported in, 6 and 7 certainly not, maybe 8 and I think thereafter yes

     

    #container {

      display: table-cell;

      width: 180px;

      height: 400px;

      background-color: #e7dbcd;

    vertical-align: middle;

    }

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points