定义和用法
white-space 属性设置如何处理元素内的空白。
这个属性声明建立布局过程中如何处理元素中的空白符。值 pre-wrap 和 pre-line 是 CSS 2.1 中新增的。
规定段落中的文本不进行换行:
p {
white-space: nowrap
}
取值
- normal: 默认。空白会被浏览器忽略。
- pre: 空白会被浏览器保留。其行为方式类似 HTML 中的 < pre > 标签。
- nowrap: 文本不会换行,文本会在在同一行上继续,直到遇到 < br > 标签为止。
- pre-wrap: 保留空白符序列,但是正常地进行换行。
- pre-line: 合并空白符序列,但是保留换行符。
- inherit: 规定应该从父元素继承 white-space 属性的值。
示例
取值结果:
- normal
<div id="div1">
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
</div>
- pre
<div id="div1">
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
</div>
- nowrap
<div id="div1">
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
</div>
- pre-wrap
<div id="div1">
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
</div>
- pre-line
<div id="div1">
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
</div>