linebreak ignored inside

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

Threaded View

there's a HTML odditity. That is, line break will be ignored inside
<pre> if the adjacent lines are tags.

see the source code and description here:

if anyone know the spec for XML case, please let me know. Thanks.

88=91 /

Re: linebreak ignored inside

Quoted text here. Click to load it

The problem is that line breaks are treated in a special way inside a
PRE block. Outside a PRE block line breaks count as normal space
characters and therefore they should be ignored before/after end tags or
start tags because usually one would add line breaks into the source
code just there to make the code more readable. Also any sequence of
space characters, tabs and line breaks (the so called "white spaces")
will be treated as a single space character.

Inside a PRE block, line breaks characters and all other "white space"
characters are treated differently. They do not copllapse into a single
space character, and line breaks must be displayed where they occur and
won't convert into a space character. So I think that Firefox and Safari
don't display your test page correctly.

The problem seems to be the "display:table" for the PRE tag, which
is confusing Firefox and Safari. This is probably a bug in these

I assume that you want to use display:table to make the box a small as
needed. Without the modified display property the box would span the
available width completly. You could make the box a float instead and
"clear" it afterwards to get the same effect. And then all browsers
would display it right.


Re: linebreak ignored inside

Xah Lee wrote:
Quoted text here. Click to load it

Why this construct?  I was surprised to see that most browsers seem to
handle it. It seems somewhat odd to me apply such styling as display to
pre. My experience that practically the only styling appropriate to pre
is to the font.

(BTW IE does not recognise the table value for display)

To have the pre element space restrained you might take the styling off
pre and declare it  in a div (or other element)

<div class="lyrics">


Re: linebreak ignored inside

boclair wrote:

Quoted text here. Click to load it

Overflow styling on <pre> is both commonplace and useful.

Jack. /

Re: linebreak ignored inside

Jack wrote:
Quoted text here. Click to load it

I didn't know it was commonplace.

The basic reason I feel that styling of pre should be restricted is to
font properties is because it is somewhat unique being "preformatted".


Re: linebreak ignored inside

Quoted text here. Click to load it

On your page that explains the problem, you quote the text "a line break
immediately following a start tag must be ignored, as must a line break
immediately before an end tag" from the HTML specification. The cited
requirement has, however, generally been violated by web browsers, so don't
count on it - but don't get surprised either if some browser actually
complies with it in some situation.

The original problem appears to be how to present poetry. Using <pre> isn't
really the best tool for it. Do you want your poem to appear in a monospace
font when your style sheet is ignored?

A better approach is to use

<div class="stanza">
<div>first line</div>
<div>second line</div>

together with a suitable piece of CSS that tries to prevent line breaks
(except between the <div> elements) and may add colors or whatever you want.
Using this approach, each line is a stylable element, and you may add class
attributes for finer tuning. Moreover, you can add, say,
div.stanza div { margin-left: 1em; text-indent: -1em; }
so that if a line is divided, the continuation line appears with a little
indentation, so that the reader can still see the structure.

Followups trimmed.

Jukka K. Korpela ("Yucca")

Site Timeline