Re: WIDTH attribute for peformatted text

Discussion in 'HTML' started by Toby Inkster, Oct 1, 2005.

  1. Toby Inkster

    Toby Inkster Guest

    Jud McCranie wrote:

    > OK, then what is the best way to have fixed-width text, with a
    > parameter telling the width of the line (so the browser can adjust the
    > size to get wide lines all on the screen)?


    You could use CSS 2.1's "white-space:pre-wrap" which basically means
    "treat this like <pre>, but wrap lines if it's really needed".

    <pre style="white-space:pre-wrap">
    Blah. Preformatted text goes here. Blah.
    </pre>

    Downside is that it doesn't work in Internet Explorer.

    Alternatively, you could use PHP's wordwrap() function:

    <? ob_start(); ?>
    Blah. Preformatted text goes here. Blah.
    <?
    $x = ob_get_contents();
    ob_end_clean();
    printf ("<pre>%s</pre>\n", wordwrap($x,76));
    ?>

    Downside there is that the width is fixed at 76 characters, which may or
    may not be appropriate for the visitor's browser width.

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
    Now Playing ~ ./andreas_johnson/liebling/05_should_have_been_me.ogg
    Toby Inkster, Oct 1, 2005
    #1
    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. AndrewF
    Replies:
    1
    Views:
    759
    Bruce Barker
    Oct 10, 2005
  2. Jonathan N. Little

    Re: WIDTH attribute for peformatted text

    Jonathan N. Little, Oct 1, 2005, in forum: HTML
    Replies:
    1
    Views:
    321
    Jud McCranie
    Oct 1, 2005
  3. Jud McCranie
    Replies:
    16
    Views:
    631
    Jukka K. Korpela
    Oct 3, 2005
  4. Blinky the Shark

    Re: WIDTH attribute for peformatted text

    Blinky the Shark, Oct 1, 2005, in forum: HTML
    Replies:
    5
    Views:
    327
    Blinky the Shark
    Oct 3, 2005
  5. Coder
    Replies:
    1
    Views:
    693
    Cowboy \(Gregory A. Beamer\)
    Jun 24, 2006
Loading...

Share This Page