Page 1 of 3 123 LastLast
Results 1 to 10 of 27

Thread: align text

  1. #1
    Join Date
    Aug 2006
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default align text

    hey, Im currently have a td and inside that td I got two text fields that I want on each side (right and left) but I cant get the text to align with a normal p tag
    this is what it looks like now:
    Code:
    <td width="400"><p align="left">text 1</p><p align="right">text 2</p></td>
    this is bugging me a lot because I cant use td's at this place so I would appreciate if someone could help me out here

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Ugh, presentational markup! This can't be done in HTML anyway, you need CSS and float:
    Code:
    td.bothsides {
      width: 400px; // but, pixel measurements are bad!
    }
    
    td.bothsides p {
      width: 46&#37;;
      margin: 1%;
    }
    
    td.bothsides p.left {
      float: left;
      text-align: left;
    }
    
    td.bothsides p.right {
      float: right;
      text-align: right;
    }
    Code:
    <td class="bothsides">
      <p class="left">
        text 1
      </p>
      <p class="right">
        text 2
      </p>
    </td>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    Quote Originally Posted by Dennis_Gull View Post
    this is bugging me a lot because I cant use td's at this place
    Thank God. Would you like how to do this in div's instead?
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

  4. #4
    Join Date
    Aug 2006
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the reply, the code you provided works when I use a td tag but after i made this post I changed everything to a div tag =/

    Quote Originally Posted by alexjewell View Post
    Thank God. Would you like how to do this in div's instead?
    actually I was just going to write that :P
    Im working with ajax at the moment and Im making a suggest box under the search field but I want some of the info to be on the right side (like google suggest) and all I have is a div tag and then I use innerHTML to place the data like this: (ignore class="none" its because the box is inactive)

    Code:
    <div id="search_bar" class="none"></div>
    and in the innerHTML it looks like this (cleaned from scripts):
    Code:
    looping...
    <div>text 1 , text 2 (should be align right), text 3 (should be align right)</div>
    looping...
    The reason I didnt place text 2 and 3 in div tags is because div tags take up a new row but then I remembered that I could use display: inline; but heres the funny part, if i use that option the align right somehow doesnt work...

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Use float like I did. Inline elements can't have text-align; you need a floated block-level element.
    then I use innerHTML
    innerHTML is non-standard, destroys event handlers, leads to ugly, markup-dependent code, and doesn't work in XHTML. Avoid it.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Aug 2006
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    isnt innerHTML the only way to update parts of the page with help from with ajax?

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Of course not. Use the DOM methods instead.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Twey is a bit extreme on innerHTML. He is so good at most other things, we forgive him. One must be careful with it though, just as one must correctly use any other object in javascript, with awareness of its side effects and limitations.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    There are times and places where innerHTML is necessary. However, this is not one of them, and its limitations are such that it should be avoided wherever possible.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    Aug 2006
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for all the replys I got everything to work now with float, it looks like this:


    I will also take a look at the link about DOM you gave me jscheuer1, I followed some tutorials on sitepoint before I read the book about ajax and they said that DOM often were slower then innerHTML so I never really took much of an interest in DOM.
    But isn't it almost the same thing just that you create tags with createElement?

    edit:
    found a link with the benchmark on the different methods but maybe it doesn't matter when its such a small functions we're talking about.
    http://www.quirksmode.org/dom/innerhtml.html
    Last edited by Dennis_Gull; 07-14-2007 at 06:25 PM.

Bookmarks

Posting Permissions

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