<pre> and wordwrap

Discussion in 'HTML' started by Christoph, Sep 23, 2006.

  1. Christoph

    Christoph Guest

    I have a large amount of text that is getting pulled from a file. It looks
    something like this:

    'large amount of text 90+ characters long

    large amount of text 90+ characters long

    large amount of text 90+ characters long'

    If I don't enclose the text in a <pre> tag, all the CRLFs are stripped and
    all the text runs together. If I do put it in a <pre> tag, the text goes
    off the right side of the screen and causes a scroll bar to appear on the
    browser (due to where the text is positioned, by necessity, on the page).
    So is there something I can do, using CSS or anything else, that gives me
    the best of both worlds? That will (effectively) keep the CRLFs and also
    wrap the text?

    thnx,
    Christoph
     
    Christoph, Sep 23, 2006
    #1
    1. Advertising

  2. Christoph

    Toby Inkster Guest

    Christoph wrote:

    > If I don't enclose the text in a <pre> tag, all the CRLFs are stripped and
    > all the text runs together. If I do put it in a <pre> tag, the text goes
    > off the right side of the screen and causes a scroll bar to appear


    The CSS answer is "white-space:pre-wrap" which is in the CSS 2.1 draft,
    but it's not widely supported by browsers.

    The alternative is to use server-side scripting to format the text
    appropriately. There are two ways to do this:

    1. Use PHP's wordwrap() function (or an equiv function in another
    language) to ensure that no lines are too long, before dumping it
    all into a <pre>...</pre> block; or

    2. Use PHP's nl2br() function (or equiv) to convert the existing
    line breaks into <br> tags, then dump the whole thing into a
    <div>...</div> block.

    The second solution is probably a better idea, because it allows the
    browser to do its own word wrapping. The browser will almost certainly do
    a better job at wrapping than the server would have.

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
     
    Toby Inkster, Sep 23, 2006
    #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. =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=

    Wordwrap DataGrid Columns

    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=, Nov 3, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    3,833
    Saravana
    Nov 4, 2004
  2. Harvey Triana

    GridView without wordwrap

    Harvey Triana, Apr 3, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    532
    Harvey Triana
    Apr 3, 2006
  3. Matt
    Replies:
    1
    Views:
    524
    Sid Ismail
    Dec 23, 2004
  4. =?Utf-8?B?Z3V5?=

    GridView forcing wordwrap

    =?Utf-8?B?Z3V5?=, Oct 29, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    581
    Cowboy \(Gregory A. Beamer\)
    Oct 29, 2007
  5. luke
    Replies:
    7
    Views:
    130
Loading...

Share This Page