Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Aug 2004
    Location
    Nashville
    Posts
    202
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Centering Text in CSS.

    What's the appropriate way to vertically center a line of text inside a css <div>

    I realize that <center></center> doesn't validate.

    Thanks

    JW

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    I believe its: text-align: center;

  • #3
    Senior Coder chilipie's Avatar
    Join Date
    Jul 2004
    Location
    Shrewsbury, UK Age: 16
    Posts
    1,117
    Thanks
    0
    Thanked 0 Times in 0 Posts
    He said to vertically center text...

    Say you have a div that is 500px high. This is how you would get the text in the center (horizontally and vertically).

    CSS:
    Code:
    div.500 {
    height: 500px;
    width: 500px;
    }
    
    p.centered {
    text-align: center;
    line-height: 500px;
    }
    HTML:
    Code:
    <div class="500">
    <p class="centered">Centered text.</p>
    </div>

  • #4
    Senior Coder
    Join Date
    Nov 2003
    Location
    Minneapolis, MN
    Posts
    2,879
    Thanks
    2
    Thanked 65 Times in 56 Posts
    How to vertically align something? I wonder if this has been asked before...

    * harp music and a slow fade to.... *

    vertical-align not working...



  •  

    Posting Permissions

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