with other tags 

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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?


Re: duplicating
 with other tags 

Deciding to do something for the good of humanity, John O'Conner

Quoted text here. Click to load it

Why? By who? Certainly not the W3C.

Quoted text here. Click to load it

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:

code here

Mark Parnell
My Usenet is improved; yours could be too:

Re: duplicating
 with other tags 

Quoted text here. Click to load it

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

Quoted text here. Click to load it

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

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

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")

Re: duplicating
 with other tags 

John O'Conner wrote:

Quoted text here. Click to load it

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

Quoted text here. Click to load it

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
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>

Site Timeline