Alex Rivera | Logout

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

Asked 2010-12-30T04:35:39.033
68

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

Edit
Report

2 Answers

46

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.

answered 2012-08-30T19:44:14.417
4

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

answered 2010-12-30T04:39:42.510

Your Answer