Skip to content

white-space ​

描述 ​

white-space CSS 属性设置如何处理元素内的空白。

效果展示 ​

语法 ​

css
/* Single keyword values */
white-space: normal;
white-space: nowrap;
white-space: pre;
white-space: pre-wrap;
white-space: pre-line;
white-space: break-spaces;

/* white-space-collapse and text-wrap shorthand values */
white-space: collapse balance;
white-space: preserve nowrap;

值 ​

  • normal 与 normal 一样折叠空白,但抑制源中的换行符(文本换行)。
  • pre 空白序列被保留。仅在源中的换行符和 <br> 元素处断行。
  • pre-wrap 空白序列被保留。行在换行符、 <br> 处断行,并根据需要填充行框。
  • pre-line 空白序列被折叠。行在换行符、 <br> 处断行,并根据需要填充行框。
  • break-spaces 该行为与 pre-wrap 相同,除了:任何保留的空白序列总是占用空间,包括在行尾。每个保留的空白字符之后(包括空白字符之间)都存在换行机会。这种保留的空间会占用空间并且不会悬挂,从而影响盒子的固有尺寸( min-content 尺寸和 max-content 尺寸)。
  • flex 这是描述