Is it possible to make any CSS element behave like <pre>

HtmlCssPre

Html Problem Overview


I am loading some content inside an iframe. I want this content to behave as-if it was inside a <pre> tag - namely for it to respect line breaks. I am using javascript to set the style of the body element of this iframe.

I am wondering if it would be possible to set a particular style that will cause the body of this iframe to act like it's inside <pre/>.

Html Solutions


Solution 1 - Html

you can find the default setting or how they're suppose to be at http://www.w3.org/TR/CSS2/sample.html just apply the same style to the element you want to behave as a pre element and voila you're done

p.s. which is basically

pre{ white-space: pre ; display: block; unicode-bidi: embed }

Solution 2 - Html

If you're only interested in preserving line breaks but not whitespace then I suggest using:

body {
    white-space: pre-line;
}

This will collapse multiple consecutive white space characters into one but preserve line breaks. The downside is that it's only supported in IE versions 8 and up.

Solution 3 - Html

Try setting the element's white-space style to a value of pre.

body {
    white-space: pre;
}

Solution 4 - Html

If you just want it to act on linebreaks like pre, use the css: white-space: pre

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionchaimpView Question on Stackoverflow
Solution 1 - HtmlBreezerView Answer on Stackoverflow
Solution 2 - HtmlHjorthView Answer on Stackoverflow
Solution 3 - HtmlsteveloveView Answer on Stackoverflow
Solution 4 - HtmlKeltexView Answer on Stackoverflow