The white-space
CSS-3 中的属性有pre-wrap
值,它将保留空格和换行符,并在必要时换行,并且pre-line
value,它会折叠空白,但保留换行符,并在必要时换行。
它能做什么not不过,有一个值果酱空白和崩溃换行,同时仍然换行。
是否可以使用其他 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
(prove https://css-tricks.com/almanac/properties/w/whitespace/ for white-space
)
There is no line such as: collapse | preserve | ...
唯一的方法是使用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.
硬编码方法
1st
* {
white-space: pre-wrap;
}
br {
display: none;
}
This example<br/>code<br/>should render<br/>on one line but<br/>with spaces intact.<br/>
2nd
This example
code
should render
on one line but
with spaces intact.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)