我正在尝试使用 css white-space 在 div 中显示带有换行符的文本值为 pre-line
的属性。这在 Chrome、Firefox 和 IE 8 中按预期工作,但在 IE 7 中无效。
例如,
<div style="white-space:pre-line">
CSS has a pretty useful property called white-space that I’m guessing goes unnoticed among CSS beginners.
You can probably live without this property for quite some time, but once you learn how to use it, it will come in very handy and you’ll find yourself going back to it over and over again.
</div>
将在 Chrome、Firefox 和 IE 8 中显示如下:
CSS has a pretty useful property called white-space that I’m guessing goes unnoticed among CSS beginners.
You can probably live without this property for quite some time, but once you learn how to use it, it will come in very handy and you’ll find yourself going back to it over and over again.
但在 IE 7 中它显示如下:
CSS has a pretty useful property called white-space that I’m guessing goes unnoticed among CSS beginners. You can probably live without this property for quite some time, but once you learn how to use it, it will come in very handy and you’ll find yourself going back to it over and over again.
你可以在这里看到:http://jsfiddle.net/VSQnP/10/ .
我已经尝试了 pre
的值,但是文本没有换行并且长行超出了 div 的右侧,而 pre-wrap
,但这在 IE 7 中有同样的问题。
最佳答案
IE7 不支持空白处理属性 pre-line
。看这个page兼容性表。
您可以改用这些声明
white-space: pre;
word-wrap: break-word;
它不是 pre-line
的替代品,因为它会打断单词而不是行,但至少内容不会超出其容器的边界。
关于css - 在 IE 7 中是否有替代 CSS white-space 属性的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5163379/