1. 排版
  2. 空白处理

排版

white-space

用于控制元素的白空间属性的工具类。

ClassStyles
whitespace-normal
white-space: normal;
whitespace-nowrap
white-space: nowrap;
whitespace-pre
white-space: pre;
whitespace-pre-line
white-space: pre-line;
whitespace-pre-wrap
white-space: pre-wrap;
whitespace-break-spaces
white-space: break-spaces;

示例

正常

使用 whitespace-normal 工具类使文本在元素内正常换行。换行符和空格将被折叠:

Hey everyone! It’s almost 2022 and we still don’t know if there are aliens living among us, or do we? Maybe the person writing this is an alien. You will never know.

<p class="whitespace-normal">Hey everyone!It's almost 2022       and we still don't know if there             are aliens living among us, or do we? Maybe the person writing this is an alien.You will never know.</p>

不换行

使用 whitespace-nowrap 工具类防止文本在元素内换行。换行符和空格将被折叠:

Hey everyone! It’s almost 2022 and we still don’t know if there are aliens living among us, or do we? Maybe the person writing this is an alien. You will never know.

<p class="overflow-auto whitespace-nowrap">Hey everyone!It's almost 2022       and we still don't know if there             are aliens living among us, or do we? Maybe the person writing this is an alien.You will never know.</p>

保持格式

使用 whitespace-pre 工具类保留元素内的换行符和空格。文本不会换行:

Hey everyone! It’s almost 2022 and we still don’t know if there are aliens living among us, or do we? Maybe the person writing this is an alien. You will never know.

<p class="overflow-auto whitespace-pre">Hey everyone!It's almost 2022       and we still don't know if there             are aliens living among us, or do we? Maybe the person writing this is an alien.You will never know.</p>

保持换行

使用 whitespace-pre-line 工具类保留换行符但不保留空格。文本将正常换行:

Hey everyone! It’s almost 2022 and we still don’t know if there are aliens living among us, or do we? Maybe the person writing this is an alien. You will never know.

<p class="whitespace-pre-line">Hey everyone!It's almost 2022       and we still don't know if there             are aliens living among us, or do we? Maybe the person writing this is an alien.You will never know.</p>

包裹格式

使用 whitespace-pre-wrap 工具类保留换行符和空格。文本将正常换行:

Hey everyone! It’s almost 2022 and we still don’t know if there are aliens living among us, or do we? Maybe the person writing this is an alien. You will never know.

<p class="whitespace-pre-wrap">Hey everyone!It's almost 2022       and we still don't know if there             are aliens living among us, or do we? Maybe the person writing this is an alien.You will never know.</p>

符号换行

使用 whitespace-break-spaces 工具类保留换行符和空格。行末的空白不会悬挂,而是会换到下一行:

Hey everyone! It’s almost 2022 and we still don’t know if there are aliens living among us, or do we? Maybe the person writing this is an alien. You will never know.

<p class="whitespace-break-spaces">Hey everyone!It's almost 2022       and we still don't know if there             are aliens living among us, or do we? Maybe the person writing this is an alien.You will never know.</p>

响应式设计

Prefix a white-space utility with a breakpoint variant like md: to only apply the utility at medium screen sizes and above:

<p class="whitespace-pre md:whitespace-normal ...">  Lorem ipsum dolor sit amet...</p>

Learn more about using variants in the variants documentation.