white-space属性

定义和用法

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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值