Skip to main content
Participant
February 1, 2009
Question

Measuring the length of a piece of text

  • February 1, 2009
  • 2 replies
  • 361 views
Hi,

I'm trying to take a piece of a longer text and display it so that it is exactly 4 lines long and 200 pixels wide. If I use the regular text string functions (right, left, mid, etc.) I can create 4 lines with a certain number of characters, but depending on the text, sometimes they are too long or so short that I could have fit another word on the line. Is there a function that takes into account the actual linear length in pixels of a line of text formatted in the current style? Also the original text could have HTML codes in it, so I would want to ignore these when selecting the text so that I don't count non-displaying characters or leave open ended HTML in my page.

If I have the wrong approach, any guidance would be appreciated.
    This topic has been closed for replies.

    2 replies

    Inspiring
    February 2, 2009
    Participating Frequently
    February 2, 2009
    just simply put an DIV around the long text you want to display. and make the style to whitespace to nowrap.

    for example:

    <div style="white-space:nowrap;"><cfoutput>#yourLongTextHere#</cfoutput></div>