目录

CSS white-space 属性


示例

演示空白属性的不同值:

p.a {
  white-space: nowrap;
}

p.b {
  white-space: normal;
}

p.c {
  white-space: pre;
}
亲自试一试 »

定义和用法

这个white-space属性指定如何处理元素内的空白。

展示演示❯

默认值: 普通的
遗传: 是的
可动画: 不。阅读可动画的
版本: CSS1
JavaScript 语法: 对象.style.whiteSpace="nowrap"尝试一下

浏览器支持

表中的数字指定完全支持该属性的第一个浏览器版本。

Property
white-space 1.0 8.0 3.5 3.0 9.5


CSS 语法

white-space: normal|nowrap|pre|pre-line|pre-wrap|initial|inherit;

属性值

Value Description Demo
normal Sequences of whitespace will collapse into a single whitespace. Text will wrap when necessary. This is default Demo ❯
nowrap Sequences of whitespace will collapse into a single whitespace. Text will never wrap to the next line. The text continues on the same line until a <br> tag is encountered Demo ❯
pre Whitespace is preserved by the browser. Text will only wrap on line breaks. Acts like the <pre> tag in HTML Demo ❯
pre-line Sequences of whitespace will collapse into a single whitespace. Text will wrap when necessary, and on line breaks Demo ❯
pre-wrap Whitespace is preserved by the browser. Text will wrap when necessary, and on line breaks Demo ❯
initial Sets this property to its default value. Read about initial
inherit Inherits this property from its parent element. Read about inherit

相关页面

CSS教程:CSS 文本间距

HTML DOM 参考:空白属性