Results 1 to 7 of 7

Thread: Help getting pixel width of string

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Three Anchor Bay, Cape Town, South Africa
    Posts
    769

    Help getting pixel width of string

    Hi,

    I have a string in a table cell. Fistly, I want the cell not to wrap. I also want it so that, if the content of the cell will not fit without extending the cell, the content will either be totaly or partially hidden.

    Javascript code, html solution needed. Thanx.

    I am using the following for my no wrap, but I would like to know the style sheet syntax if anyone knows it:

    Code:
    <td nowrap></td>

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Three Anchor Bay, Cape Town, South Africa
    Posts
    769
    just for interest sake, I tried using the following in the hope that the html would do the work for me:

    Code:
    <td colspan=3 style="width : 1px;" nowrap>
        <div width=100% style="overflow: hidden;" nowrap>January 2002</div>
    </td>

  3. #3
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    If I understand you right this may work:

    Code:
    <td style="width : 50px; white-space:nowrap; overflow:hidden;">
        January 2002
    </td>

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Three Anchor Bay, Cape Town, South Africa
    Posts
    769
    Thanks for reply, bu alas, it did not do what I'm looking for.

    Also Note: browser = IE6

  5. #5
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    Oh sorry, I'm out of ideas then The no wrap thing worked in mozilla but not the overflow. I think it's because overflow only applies to "block-level and replaced elements", I suppose that's not a table cell.

  6. #6
    Addicted Member Martin Wilson's Avatar
    Join Date
    Mar 2002
    Location
    :)
    Posts
    236
    This seems to work:
    Code:
    <table style="table-layout: fixed">
      <tr>
        <td style="width:20px">
          <div style="white-space:nowrap">
            Testing how this works
          </div>
        </td>
      </tr>
    </table>

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Three Anchor Bay, Cape Town, South Africa
    Posts
    769
    I have not found a solution to checking the pixel width of the string, but I found a work around. The cells I am using are all fixed widths, so I am just checking to see if the width is greater than the one that I specified. If it is, then I hide the contents of the cell. Thanks guys.

Posting Permissions

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



Click Here to Expand Forum to Full Width