开发者

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

开发者 https://www.devze.com 2023-02-01 23:18 出处:网络
I am loading some content inside an iframe.I want this con开发者_Go百科tent to behave as-if it was inside a <pre> tag - namely for it to respect line breaks.I am using javascript to set the styl

I am loading some content inside an iframe. I want this con开发者_Go百科tent 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/>.


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 }


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.


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

body {
    white-space: pre;
}


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

0

精彩评论

暂无评论...
验证码 换一张
取 消