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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jan 2008
    Posts
    334
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Aligning text with classes

    What is the reason behide you not being able to align text with with a class but only with ids. Here is a example code:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <style type="text/css">
    .title {
    text-align:center;
    font-size:26px;
    }
    </style>
    </head>
    <body>
    <span class="title">texting...</span>
    </body>
    </html>
    I've tried this and the text wont align to the center. What is the reason behide that? I also found that it wont do it with <h1> as well.

  • #2
    Regular Coder
    Join Date
    May 2008
    Posts
    135
    Thanks
    13
    Thanked 10 Times in 10 Posts
    you are telling an inline element to align centre. try setting the elements display to block then centre it. ( display:block ). the block if no width defined should span across the page and the text should be centred inside the block. or alternatively, put these inline elements in a block element like a div and text-align:center on the div.

    I've tried this and the text wont align to the center. What is the reason behide that? I also found that it wont do it with <h1> as well.
    i believe its because they are inline elements.

    so in your example above to get the span to align centre, you would need to put text-align:center; on the body.
    Last edited by mike182uk; 06-16-2009 at 08:54 AM.

  • #3
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Setting a border around the targeted elements may reveal you the difference between the behavior of inline and block level elements.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

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