How can I force clipping of text in a table cell?

Discussion in 'ASP .Net' started by john, Oct 20, 2004.

  1. john

    john Guest

    I want to set the cell width and height such that the cell doesn't get
    bigger. If the text is too long for the cell, it should be clipped. It
    only has to work for IE. I have tried setting the overflow style to
    hidden, but that doesn't work unless I set the table-layout style of
    the table to fixed, which I cannot do. In the sample code below, it
    correctly sets the width of the cell to 200, but the height gets
    bigger and it wraps the text. If I add a <nobr> tag to the cell, the
    text doesn't wrap any more, but the width gets real big (enough to fit
    all the text).

    <table width="200" border="1">
    <tr>
    <td height="20" width="200" id="tableCell" style="overflow:hidden">
    So, here is some text that obviously will not fit in this lousy 200
    pixel wide box.
    </td>
    </tr>
    </table>

    Thanks in advance.
     
    john, Oct 20, 2004
    #1
    1. Advertising

  2. Not sure this is the best forum for this but I will answer with .Net solution.

    Find out the make number of characters that can fit in the and use substring to trim those values.

    For example:

    string test = "this is a test that should only be 10 characters long";
    test = test.Substring(0, 10);

    This is assuming that your cell is wide enough to fit 10 characters.

    Alan Washington
    http://www.aewnet.com

    > I want to set the cell width and height such that the cell doesn't get
    > bigger. If the text is too long for the cell, it should be clipped. It
    > only has to work for IE. I have tried setting the overflow style to
    > hidden, but that doesn't work unless I set the table-layout style of
    > the table to fixed, which I cannot do. In the sample code below, it
    > correctly sets the width of the cell to 200, but the height gets
    > bigger and it wraps the text. If I add a <nobr> tag to the cell, the
    > text doesn't wrap any more, but the width gets real big (enough to fit
    > all the text).
    >
    > <table width="200" border="1">
    > <tr>
    > <td height="20" width="200" id="tableCell" style="overflow:hidden">
    > So, here is some text that obviously will not fit in this lousy 200
    > pixel wide box.
    > </td>
    > </tr>
    > </table>
    >
    > Thanks in advance


    User submitted from AEWNET (http://www.aewnet.com/)
     
    alan.washington, Oct 20, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve
    Replies:
    3
    Views:
    4,176
    Steve
    Jan 22, 2004
  2. Phillip Roncoroni
    Replies:
    14
    Views:
    1,113
    Toby A Inkster
    Apr 5, 2004
  3. humbads
    Replies:
    4
    Views:
    1,253
    Shailesh Humbad
    Feb 16, 2006
  4. Peter Otten

    Tkinter: Clipping a canvas text item

    Peter Otten, Feb 21, 2004, in forum: Python
    Replies:
    4
    Views:
    599
  5. sdf
    Replies:
    3
    Views:
    1,959
Loading...

Share This Page