duplicating <pre> with other tags

Discussion in 'HTML' started by John O'Conner, Aug 1, 2006.

  1. I've been told that I can no longer use pre-tags for code sample text.
    It's a bummer, but I can't change the decision.

    My question is this: how can I duplicate the pre-tag functionality with
    other tags...maybe the p-tag with some css styling? The problem I'm
    having with the p-tag is getting each line to break without <br>. Is
    there a way to break lines within p-tags without the br-tag?

    Thanks,
    John
    John O'Conner, Aug 1, 2006
    #1
    1. Advertising

  2. John O'Conner

    Mark Parnell Guest

    Deciding to do something for the good of humanity, John O'Conner
    <> declared in alt.html:

    > I've been told that I can no longer use pre-tags for code sample text.


    Why? By who? Certainly not the W3C.

    > My question is this: how can I duplicate the pre-tag functionality with
    > other tags


    white-space: pre; - but support is not as good as it is for the <pre>
    element (not supported by IE<6).

    There was a discussion of this only last week or something. IIRC the
    consensus was that generally the best solution is something along the
    lines of:

    <pre><code>
    code here
    </code></pre>

    --
    Mark Parnell
    My Usenet is improved; yours could be too:
    http://blinkynet.net/comp/uip5.html
    Mark Parnell, Aug 1, 2006
    #2
    1. Advertising

  3. John O'Conner <> scripsit:

    > I've been told that I can no longer use pre-tags for code sample text.
    > It's a bummer, but I can't change the decision.


    Then ask the one who made the decision what you should use instead.

    > My question is this: how can I duplicate the pre-tag functionality
    > with other tags...


    You can create a poor man's surrogate for <pre> using messy and nonstandard
    markup:

    <div><tt><nobr>first line<br>second line<br>...<br>last
    line</nobr></tt></div>

    with each occurrence of the space character replaced by &nbsp;. Awkward, is
    it not? (The <nobr> markup is needed to prevent line breaks after hyphens
    and possibly some other special characters.)

    --
    Jukka K. Korpela ("Yucca")
    http://www.cs.tut.fi/~jkorpela/
    Jukka K. Korpela, Aug 1, 2006
    #3
  4. John O'Conner

    Andy Dingley Guest

    John O'Conner wrote:

    > I've been told that I can no longer use pre-tags for code sample text.


    This is a stupid decision. If you've had an outbreak of pointy-haired
    boss, then you have my sympathy.


    > My question is this: how can I duplicate the pre-tag functionality


    Dead easy - just use <div class="pre" > and some CSS. There's nothing
    at all magic about <pre>, it's just CSS effects.

    If you examine the W3C's suggested default stylesheet, you'll see just
    the CSS to use
    http://www.w3.org/TR/CSS21/sample.html
    The crucial bit would be
    div.pre { white-space: pre; }

    I suggest you might avoid the monospaced font in your replacement -
    that way they'll probably not notice how closely you've cloned <pre>
    :cool:
    Andy Dingley, Aug 1, 2006
    #4
    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. Rocky Moore
    Replies:
    7
    Views:
    1,721
    mikeb
    Jan 14, 2004
  2. =?Utf-8?B?S2V2aW4gQnVydG9u?=

    Pre-Send Request Headers, Pre-Send Request Content

    =?Utf-8?B?S2V2aW4gQnVydG9u?=, Dec 31, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    1,031
    =?Utf-8?B?S2V2aW4gQnVydG9u?=
    Dec 31, 2004
  3. Replies:
    3
    Views:
    621
  4. Replies:
    0
    Views:
    498
  5. Dave
    Replies:
    0
    Views:
    445
Loading...

Share This Page