[英]How to preserve whitespace but ignore line breaks in CSS?
CSS-3中的white-space
属性具有pre-wrap
值,它将保留空格和换行符,并在必要时换pre-line
,以及折叠空白的pre-line
值,但保留换行符,并在必要时换行。
它没有什么,不过,是保留空白, 崩塌换行,同时还包裹否则的值。
是否有其他CSS属性的组合可用于获得此效果?
例如:
This example
code
should render
on one line but
with spaces intact.
应该是这样的:
This example code should render on one line but with spaces intact.
回答你的问题 :不,只有使用CSS
才能做到这一点( 证明是white-space
)
唯一的方法是使用JavaScript
document.body.innerHTML = document.body.innerHTML.replace(/\\n/g, '');
html { white-space: pre-wrap; }
This example code should render on one line but with spaces intact.
硬编码方法
1
* { white-space: pre-wrap; } br { display: none; }
This example<br/>code<br/>should render<br/>on one line but<br/>with spaces intact.<br/>
第2
This example code should render on one line but with spaces intact.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.