duplicating <pre> with other tags

J

John O'Conner

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
 
M

Mark Parnell

Deciding to do something for the good of humanity, John O'Conner
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>
 
J

Jukka K. Korpela

John O'Conner said:
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.)
 
A

Andy Dingley

John said:
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:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,832
Latest member
UtaHetrick

Latest Threads

Top