Neredbojias wrote:
On 02 Sep 2008, Samuel Murray <le***@absamail.co.zawrote:
>I'm trying to find out if there is a way (perhaps using CSS) to let
this code:
<table><tr><td>One
Two
Three</td></tr></table>
display the same as if the code would have been:
<table><tr><td>One<br>
Two<br>
Three</td></tr></table>
Look into the html <preattribute.
<PREisn't an attribute; it's an element.
A <PREblock inside the <TDis not the same as inserting <BR>
elements. Some elements which may be children of <TDmay not be
children of <PRE>. User agents may, and often do, apply formatting
rules to text within a <PREblock that they don't apply (under the
default styles) to text within <TD>, such as using a monospaced typeface.
In short, this suggestion doesn't do what the OP asked for. Whether it
does what the OP *wants* is another question; and the OP might have
some success using <PREplus additional styling to render the text in
a more appropriate manner. (That assumes he doesn't need any of the
elements that <PREexcludes, such as <IMG>, inline in his <TD>s.)
If Ben's suggestion of "white-space: pre-wrap" won't work, for
example, something like the following might provide the basic feature
with better styling under capable user agents and graceful degredation
under others:
td pre {
font-family: inherit;
white-space: pre-line;
}
<table>
<tr><td><pre>
One
Two
Three
</pre></td></tr>
</table>
"pre-line" seems to me closer to the OP's original request than Ben's
suggestion of "pre-wrap", since the former collapses whitespace.
Obviously the font styling might have to be changed, depending on how
<TDis styled. "font-family: inherit" works with FF2, but not with
IE7, so "font-family: serif" (or whatever) might be a better choice.
Unfortunately, none of the UAs I tried (FF2, IE7, oOO Writer 2.4)
appear to actually support "white-space: pre-line", so to get this to
render the way I think the OP wants it, you'd have to get rid of the
extra whitespace inside the <PREblock.
But this combination does preserve the line breaks and it does degrade
gracefully; in particular, oOO Writer will preserve the line breaks,
which I gather the OP wanted. And the line breaks will be preserved
even if CSS is disabled or overridden, which is probably desirable.
--
Michael Wojcik
Micro Focus
Rhetoric & Writing, Michigan State University