css - 在 IE 7 中是否有替代 CSS white-space 属性的方法?

标签 css internet-explorer-7

我正在尝试使用 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/

相关文章:

html - 在 Adob​​e Air 应用程序中设置表单元素的样式

html - 分辨率太高时检测手机

html - IE7 中的偏移下拉菜单

css - 我有一个消失的 css 下拉菜单

css - 在 Chrome 和 Safari 中 img 后奇怪的中断,但在 Firefox 中正常

IE7/IE8 中的 CSS3 属性

css - 为什么它不应用我的 IE 样式表?

css - 水平滚动条在 ie7 和 ie8 中非常大

javascript - 如何在可滚动的 div 中创建图像

css - IE7 - 随机消失的元素